From: Jeremy McAnally Date: 2007-01-03T01:39:16+09:00 Subject: Re: Detecting default used in method calls def myfunction(a, b = nil) if (b): puts "There's a B!" else puts "Business as usual..." end end If you have more than one argument, then do something like this... def myfunction(args={}) a = args[:a] || 'my default A' b = args[:b] || 'my default B' # and so on... end myfunction(:a => 'b', :b => 'c') You can do this with merge too (i.e., build a hash with the keys A, B, and so on, and then merge it with the argument). I think there's a more graceful way to do this, but I'm too tired to find it! :( --Jeremy On 1/2/07, Peter Lynch wrote: > I would like to know if a function has been called with or without an > optional argument. > > If I have - > > def the_Function (a, b = '') > end > > and I invoke it like this - > > the_Function('a') > the_Function('a', '') > > is there any way for me to tell within the_Function which form of > invocation was used? > > -- > Posted via http://www.ruby-forum.com/. > > -- My free Ruby e-book: http://www.humblelittlerubybook.com/book/ My blogs: http://www.mrneighborly.com/ http://www.rubyinpractice.com/