From: Jeremy Bopp Date: 2010-11-19T00:46:39+09:00 Subject: Re: Multiple constructor in Ruby On 11/18/2010 9:41 AM, Arturo Bonechi wrote: > Hello! > > I have a question about the constructor in Ruby. > > Here is an exemple class : > > class Test > def initialize param > puts param > end > def initialize param1, param2 > puts "#{param1} #{param2}" > end > end > > If I call the second constructor, everything works fine, whereas I got > an 'ArgumentError: wrong number of arguments (1 for 2)' with the first. > > So, has the second constructor overriden the first one? Does that mean > you have to implement 'initialize' only once in a class? This is true for any method definition in Ruby, not just constructors. There is no facility to select methods based on method signature, so Ruby sees defining a method with the same name as an existing one as replacing or overriding the original. -Jeremy