From: Phrogz Date: 2007-11-24T13:20:01+09:00 Subject: Re: Create method using define_method with all sort of args? On Nov 23, 7:26 pm, MonkeeSage wrote: > On Nov 23, 2:23 pm, "ara.t.howard" wrote: > > > define_method 'new_method' do |some_param, *argv| > > options, *argv = argv > > options ||= {} > > > ... > > end > > Ara, > > Isn't that dangerous in case new_method is called like: > > a.new_method("a", other, args) > > ...where the optional 'option' arg is left out? It seems that your > version would consume the 'other' operand in that case. I think you'd > need to do something like I posted above to be safe. Your question implies to me that you think that if I define a method like this: def foo( name, age=0, weight=170 ) ... end that I can then call it like this: foo( "Gavin", 175 ) # use default age. In case I'm properly understanding you, then you should know that you cannot do that. You can't 'skip' an optional argument and have other optional or non-optional arguments later. So, by definition, the 'other' you use in your example is necessarily the second parameter to the method, and thus satisfies the OPs desired functionality.