From: Ara.T.Howard@... Date: 2004-11-06T03:13:41+09:00 Subject: Re: value provided for argument with default value - how to check inside method? On Sat, 6 Nov 2004, Charles Mills wrote: > On Nov 4, 2004, at 8:03 PM, itsme213 wrote: > >> Is there an equivalent of block_given? to check if the caller provided >> a >> value to an argument that had a default value? >> >> Or do I have to use some sentinel value? > > I remember Nobu had a solution for this... I can't seem to find it > though. I think it was something like this: > > > def foo(x=(nil; a=true)) > > puts a > > end > => nil > > foo() > true > => nil > > foo('value') > nil > => nil > > You can replace nil with the default value you want. a will be set to > true if a value is passed in, nil otherwise. > > -Charlie you may also use something like def foo arg, opts = {} if opts.has_key? 'x' ... end opts.update defaults ... end -a -- =============================================================================== | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov | PHONE :: 303.497.6469 | When you do something, you should burn yourself completely, like a good | bonfire, leaving no trace of yourself. --Shunryu Suzuki ===============================================================================