From: Morton Goldberg Date: 2008-02-14T02:13:59+09:00 Subject: Re: [RRR] Robert's Ruby Riddle: Local or Method 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