[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ruby-de
Subject:    Re: [ruby-de] eruby
From:       Mauricio =?iso-8859-1?Q?Fern=E1ndez?= <batsman.geo () yahoo ! com>
Date:       2003-04-06 22:10:29
[Download RAW message or body]

On Sat, Apr 05, 2003 at 11:59:44PM +0200, Tobias Pape wrote:
> 
> und was istz dieses class << foo, ich dachte vererbung sei mit
> class < foo???? 

Ist ja so :)

class << obj kann benutzt werden, um singleton Methoden zu einem Objekte
hinzuzufügen.  Die sind Methoden, die nur einem einzigen Objekte gehören.

batsman@kodos:/tmp$ expand -t2 c.rb
class A; end
a = A.new
class << a
  def foo
    puts "singleton method von a"
  end
end

a.foo

# Jetzt definieren wir eine Klassenmethode

class << A
  def foo
    puts "A.foo"
  end
  # wie
  # def A.foo; puts "A.foo" end
end

A.foo

batsman@kodos:/tmp$ ruby c.rb
singleton method von a
A.foo


-- 
 _           _                             
| |__   __ _| |_ ___ _ __ ___   __ _ _ __  
| '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ 
| |_) | (_| | |_\__ \ | | | | | (_| | | | |
|_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_|
	Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

"Who is General Failure and why is he reading my hard disk?"
Microsoft spel chekar vor sail, worgs grate !!
	-- Felix von Leitner, leitner@inf.fu-berlin.de
_______________________________________________
ruby-de mailing list
ruby-de@bttr.org
http://lists.bttr.org/mailman/listinfo/ruby-de
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic