From: Rob Biedenharn Date: 2008-01-04T01:33:20+09:00 Subject: Re: same Methode name but different Parameter On Jan 3, 2008, at 11:16 AM, Trans wrote: > On Jan 3, 10:53 am, "Salai Khine" wrote: >> Dear all, >> >> can i use in Ruby the *same Methode name but different Parameter*?? >> >> like >> >> def new (cent) >> >> end >> >> def new(euro,cent) >> >> end. > > def new(*args) > euro, cent = *args > ... > > T. or something that will actually do what you seem to want: def initialize(*args) args.unshift nil if args.size == 1 euro, cent = *args ... end You typically don't define "new" for a class, but often define "initialize" which is called by ruby after allocating the space for your new instance. You'll find it much more common in ruby to have optional trailing arguments with default values: def initialize(cent, euro=nil) ... end Then you'd have YourClass.new(centvalue, eurovalue) or just YourClass.new(centvalue) and let the euro default to nil. When things get more complicated than an optional argument or two, an options hash tends to take over. This is particularly easy to do as ruby lets you include a hash of key => value pairs at the end of an argument list without extra {} to introduce the literal hash. -Rob Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com