From: Rick DeNatale Date: 2010-06-11T07:45:16+09:00 Subject: Re: Why private #binding? On Thu, Jun 10, 2010 at 5:08 PM, Yukihiro Matsumoto wrote: > Hi, > > In message "Re: Why private #binding?" >    on Fri, 11 Jun 2010 04:57:32 +0900, Intransition writes: > > |It doesn't recognize it's receiver? > > binding returns the binding object that has info on > >  * the receiver >  * local variables >  * etc. > > but invoking it from public form does not explain the context except > for the receiver. > >                                                        matz. Yes, actually my initial thought about self was the only thing that a non-private binding method would get 'right'. The real issue, I think, is that objects in general don't have bindings, invocations do. Making Kernel#binding private means that unless you resort to trickery, it will only occur in the context of an invocation. Here's a better example: def test(code) x = 1 b = "abc".send(:binding) eval(code, b) end test("self") # => "abc" test("x") # => 1 The variable x has nothing to do with the string "abc". "abc".instance_eval is a better choice if you want to bind self in an evaluated string or block. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale