pere.noel
1/16/2006 10:08:00 AM
is it possible, in Ruby, as in Java to define two initialize methods
with dirrent type of args ?
seems not :
class AddressBook
attr_accessor :name, :phone, :address
def initialize( n, p, a)
@name = n
@phone = p
@address = a
end
def initialize( h)
@name = h['name']
@phone = h['phone']
@address = h['address']
end
end
toto = AddressBook.new("Toto", "01 23 45 67 89", "12 rue Machin 75017
Paris")
leds to :
ArgumentError: wrong number of arguments (3 for 1)
then it seems the last initialize is taken
i'd like to construct an object either from hash or sequence...
--
une bévue