From: dblack@... Date: 2007-08-10T05:42:55+09:00 Subject: Re: define_method with default parameters Hi -- On Fri, 10 Aug 2007, ara.t.howard wrote: > > On Aug 9, 2007, at 11:20 AM, Gordon Thiesfeld wrote: > >> >> Not sure if this is the most elegant way, but: >> >> define_method(:method_name) do |*args| >> parameter, parameter2 = *args >> parameter2 ||= 'default' >> puts parameter >> puts parameter2 >> end >> >> >> > > i prefer > > define_method 'method_name' do |required, *optional| > one, two, *ignored = *optional > end > > because you an error will be thrown if required is not passed and you don't > risk slurping ten arguments into 'two' You can do that just with the comma: one, two, = *optional David -- * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.com)