From: Eric Hodel Date: 2007-01-03T04:35:50+09:00 Subject: Re: Detecting default used in method calls On Jan 2, 2007, at 07:31, 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? No need to do those complicated things that everybody else is trying. Instead use an object that nobody else will pass you as a sentinel: class X SENTINEL = Object.new def the_function(a, b = SENTINEL) if b == SENTINEL then ... end end end -- Eric Hodel - drbrain@segment7.net - http://blog.segment7.net I LIT YOUR GEM ON FIRE! -- Eric Hodel - drbrain@segment7.net - http://blog.segment7.net I LIT YOUR GEM ON FIRE! -- Eric Hodel - drbrain@segment7.net - http://blog.segment7.net I LIT YOUR GEM ON FIRE!