From: Jamis Buck Date: 2004-11-06T00:33:58+09:00 Subject: Re: value provided for argument with default value - how to check inside method? itsme213 wrote: > "Robert Klemme" wrote > >>I'm unsure what you're at. Normally the idea of having a default value is >>that you don't have to worry about where it came from: >> >>def foo(x=10) >> puts x >>end >> >>Care to unveil a bit more detail why you would need that piece of >>information? > > > In this case, I want to use foo() and foo(x) as getter and setter > respectively i.e. some form of overloading. You can always do something like the following. Create a constant and initialize it to a unique object instance. Then, use that instance as the default value to your method: VALUE_NOT_SPECIFIED = Object.new def foo( x = VALUE_NOT_SPECIFIED ) case x when VALUE_NOT_SPECIFIED @x else @x = x end end Of course, someone could still explicitly pass the argument VALUE_NOT_SPECIFIED to the method, but then they would obviously be trying pretty hard to do what they aren't supposed to do... - Jamis -- Jamis Buck jgb3@email.byu.edu http://www.jamisbuck.org/jamis