Right, but no exception: initialize is an instance method. new is a
class method and after a new instance is allocated initialize is
called on that instance:
$ ruby -e 'set_trace_func lambda {|*a| p a}; Array.new'
["line", "-e", 1, nil, #<Binding:0x100f6938>, false]
["c-call", "-e", 1, :new, #<Binding:0x100f68f0>, Class]
["c-call", "-e", 1, :initialize, #<Binding:0x100f6698>, Array]
["c-return", "-e", 1, :initialize, #<Binding:0x100f6650>, Array]
["c-return", "-e", 1, :new, #<Binding:0x100f6518>, Class]
Note, there is also allocate (class method) that will create an empty
instance of the correct type. So new can be imagined as being
implemented like this:
class Class
def new(*a,&b)
o = allocate
o.initialize(*a,&b)
o
end
end
Kind regards
robert
···
2006/7/8, Damaris Fuentes <dfl_maradentro@yahoo.es>:
Um...wait...Do I have to set the name of the class before the name of
the method when this method is a class method (except the "initialize")?
--
Have a look: Robert K. | Flickr