From: dblack@... Date: 2007-08-04T07:45:53+09:00 Subject: Re: binding - how to explain it? Hi -- On Sat, 4 Aug 2007, Giles Bowkett wrote: >>> defining context. But it seems to contradict what David Black posted >>> earlier, and I saw the same thing in my own irb. >> >> I don't think it contradicts my example; I'm evaluating "puts a" >> inside a method where a has not been defined. Morton's examples >> either use the top-level binding explicitly, or set an a variable in >> the method. My example doesn't do either, so the top-level assignment >> to a is essentially playing no role. > > but why in Morton's code does the method's call to binding result in > the same binding as TOPLEVEL_BINDING, when in your code calling > binding from a method doesn't result in getting the var a which seems > to live in the top-level binding? It doesn't; there's a parameter 'a'. Here's Morton's example again: def x(a) eval(DATA.read, binding) end x(42) __END__ puts a Inside the method, a is set to 42, and in the context of that binding, "puts a" is executed. David -- * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.com)