From: Ara.T.Howard@... Date: 2004-11-06T01:03:45+09:00 Subject: Re: value provided for argument with default value - how to check inside method? On Fri, 5 Nov 2004, 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. how about something like this harp:~ > cat a.rb class C DEFAULT_X = 42 class << self def init @x = DEFAULT_X end def x arg = @x @x = arg end end self.init def initialize @x = self.class.x end def x arg = @x @x = arg end end c0 = C::new p c0.x c0.x 'forty-two' p c0.x C::x 'forty-two' # configure the class c1 = C::new p c1.x c1.x 42 p c1.x harp:~ > ruby a.rb 42 "forty-two" "forty-two" 42 regards. -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 ===============================================================================