From: ptkwt@...1.aracnet.com (Phil Tomson) Date: 2002-11-17T07:26:13+09:00 Subject: Re: Proc#binding ? In article <3DD6AC3E.1020804@path.berkeley.edu>, Joel VanderWerf wrote: >Phil Tomson wrote: >> Just a thinking out loud here, I have no pressing need for this, but... >> We've got Kernel#binding which returns the Binding object of the current >> execution context. It would seem that Proc objects also have bindings as >> well, but there is no Proc#binding method that allows us to access them. >> Should there be? > >Seems to be there in 1.7.3. But you could always implement it with eval: > >class Proc > def get_binding > eval "binding", self > end >end > >class A > def foo > x = 1 > Proc.new {} > end >end > >pr = A.new.foo > >p (eval "x", pr.binding) I think this will report a private method access error. >p (eval "x", pr.get_binding) > > Hmmm.... actually even in 1.7.3 Proc#binding seems to be a private method: irb(main):001:0> a = proc { i = 5; puts i; } # irb(main):002:0> a.binding NameError: private method `binding' called for # from (irb):2 but it looks like your get_binding method definition will work. Phil