From: John Joyce Date: 2008-02-14T01:46:42+09:00 Subject: Re: [RRR] Robert's Ruby Riddle: Local or Method On Feb 13, 2008, at 9:38 AM, Robert Dober wrote: > Hi list I was just thinking it might fun to present some of Ruby's > features in form of a riddle. > There was an interesting thread yesterday and as I always forget the > basics I wrote some testcode to find out if the local or the method > prevails, I made a stupid > error and had to rewrite the code, or maybe did I not? This depends on > the answer of the riddle. > Todays Ruby Riddle is: > > Can the following code be used to test if the argument of puts is the > local variable "a" or the method "a"? And if so please explain how. > > > a = 42 > def a; 42 end > puts a > > I leave some blank lines here so that people can reply without > spoiling if for other readers. > > > > > > > > > > > > > > > > > > > > > -- > http://ruby-smalltalk.blogspot.com/ > > --- > Whereof one cannot speak, thereof one must be silent. > Ludwig Wittgenstein > very simple puts a will out put the object a in the scope you def'd the 'a' method it belongs to either Object or IRB to get the method's output you need to do self.a