From: Robert Dober Date: 2008-02-14T02:58:17+09:00 Subject: Re: [RRR] Robert's Ruby Riddle: Local or Method On Feb 13, 2008 6:13 PM, Morton Goldberg wrote: > On Feb 13, 2008, at 10:38 AM, Robert Dober wrote: > > > 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 can't see how it can as it is written above, but with a little > modification ... > > > a = 42 > def a; 43 end > puts a > puts a() > > > This makes it clear that Ruby prefers the local variable when it's > defined. It also makes it clear that one doesn't have to write self.a > to get the method called. > > > # a = 42 > def a; 43 end > puts a > puts a() > > > And this makes it clear that Ruby will call the method when the local > is not defined. > > Regards, Morton > > No Morton, there is a perfect solution with the code snippet I posted... it is simple, I will tell you later R. -- http://ruby-smalltalk.blogspot.com/ --- Whereof one cannot speak, thereof one must be silent. Ludwig Wittgenstein