From: Robert Klemme Date: 2009-08-20T21:55:10+09:00 Subject: Re: #has_arguments? 2009/8/20 Robert Klemme : > 2009/8/20 Brian Candler : >> Robert Klemme wrote: >>> As a side note: I see this sometimes >>> >>> def m(a = nil) >>>   @a = a.nil? ? 123 : a >>> end >>> >>> which is of course silly.  The same would be much better expressed as >>> >>> def m(a = 123) >>>   @a = a >>> end >> >> No, it's not the same. > > Can you explain what the differences are? > >> Consider: >> >>  def foo(a = nil) >>    m(a) >>  end >> >>  foo() > > I do not see the connection of this to what I posted. Argh! Now I see what you mean. If you use nil as universal "absence" marker then you have to declare the default only inside the method when doing the a.nil? logic because you will pass it through from calling methods. I only considered a single method and did not have nested calls in mind. Do you believe that these are common enough to warrant making this a common pattern? Btw, we can also do this: def foo(*a) bar(*a) end def bar(a = 123) @a = a end Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/