From: Intransition on 10 Jun 2010 00:38 Why is #binding a private method? I end up doing a lot of this: class Scope def __binding__ binding end end In order to setup a scope for ERB evaluation, among other uses.
From: Rick DeNatale on 10 Jun 2010 09:29 On Thu, Jun 10, 2010 at 12:38 AM, Intransition <transfire(a)gmail.com> wrote: > Why is #binding a private method? I end up doing a lot of this: > > class Scope > def __binding__ > binding > end > end > > In order to setup a scope for ERB evaluation, among other uses. I can think of two potential reasons. 1. Because binding exposes the internals of the receiver. 2. because if it were public then in a case like: class A def self.binding_of(b) b.binding end end A.binding_of("abc") might well return a binding with self == A, rather than the string, because binding returns the bindings "at the point of call" -- 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
From: Yukihiro Matsumoto on 10 Jun 2010 13:01 Hi, In message "Re: Why private #binding?" on Thu, 10 Jun 2010 22:29:32 +0900, Rick DeNatale <rick.denatale(a)gmail.com> writes: |I can think of two potential reasons. | |1. Because binding exposes the internals of the receiver. | |2. because if it were public then in a case like: | | |class A | def self.binding_of(b) | b.binding | end |end | |A.binding_of("abc") | |might well return a binding with self == A, rather than the string, |because binding returns the bindings "at the point of call" The latter one was the biggest reason for me. matz.
From: Rick DeNatale on 10 Jun 2010 13:09 On Thu, Jun 10, 2010 at 1:01 PM, Yukihiro Matsumoto <matz(a)ruby-lang.org> wrote: > Hi, > > In message "Re: Why private #binding?" > on Thu, 10 Jun 2010 22:29:32 +0900, Rick DeNatale <rick.denatale(a)gmail.com> writes: > > |I can think of two potential reasons. > | > |1. Because binding exposes the internals of the receiver. > | > |2. because if it were public then in a case like: > | > | > |class A > | def self.binding_of(b) > | b.binding > | end > |end > | > |A.binding_of("abc") > | > |might well return a binding with self == A, rather than the string, > |because binding returns the bindings "at the point of call" > > The latter one was the biggest reason for me. Knowing you, I suspected that that was the case. It would be for me as well. -- 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
From: Intransition on 10 Jun 2010 15:57 On Jun 10, 1:01 pm, Yukihiro Matsumoto <m...(a)ruby-lang.org> wrote: > Hi, > > In message "Re: Why private #binding?" > on Thu, 10 Jun 2010 22:29:32 +0900, Rick DeNatale <rick.denat...(a)gmail.com> writes: > > |I can think of two potential reasons. > | > |1. Because binding exposes the internals of the receiver. > | > |2. because if it were public then in a case like: > | > | > |class A > | def self.binding_of(b) > | b.binding > | end > |end > | > |A.binding_of("abc") > | > |might well return a binding with self == A, rather than the string, > |because binding returns the bindings "at the point of call" > > The latter one was the biggest reason for me. It doesn't recognize it's receiver?
|
Next
|
Last
Pages: 1 2 3 Prev: weird action of 'nokogiri' library on Snow Leopard Next: How to implement fork cocept in ruby |