From: Martin DeMello Date: 2008-02-14T03:31:21+09:00 Subject: Re: [RRR] Robert's Ruby Riddle: Local or Method On Feb 13, 2008 9:08 PM, 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 leave some blank lines here so that people can reply without > spoiling if for other readers. Here be spoiler: > > > > > > > > > > > > > > > > > martin@dabba ~ $ cat puzzle.rb a = 42 def a; 42 end puts a martin@dabba ~ $ ruby -r profile puzzle.rb 2>&1 | grep "Object#a" martin@dabba ~ $ tail -2 puzzle.rb > puzzle1.rb martin@dabba ~ $ cat puzzle1.rb def a; 42 end puts a martin@dabba ~ $ ruby -r profile puzzle1.rb 2>&1 | grep "Object#a" 0.00 0.13 0.00 1 0.00 0.00 Object#a martin