From: Daniel Schierbeck Date: 2006-07-25T20:10:08+09:00 Subject: Re: Defining a method with an argument with a default value Pedro C�rte-Real wrote: > I have this line in a class method to define an initializer: > > define_method(:initialize){|value| @value = value} > > But I want something more like this: > > define_method(:initialize){|value=nil| @value = value if value} First of all, you don't need the `if value' part -- when Ruby sees @value, it is immediately created, with the value nil, so there's no problem with giving it the value nil explicitly. Second, I believe you can just do this: define_method(:initialize){|value| @value = value} If #initialize is called with no arguments, `value' will just be nil, although IRB may issue a warning. Cheers, Daniel