Why private #binding?

I

Intransition

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.
 
R

Rick DeNatale

Why is #binding a private method? I end up doing a lot of this:

=A0class Scope
=A0 =A0def __binding__
=A0 =A0 =A0binding
=A0 =A0end
=A0end

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 =3D=3D A, rather than the string,
because binding returns the bindings "at the point of call"


--=20
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
 
R

Rick DeNatale

Hi,

In message "Re: Why private #binding?"
=A0 =A0on Thu, 10 Jun 2010 22:29:32 +0900, Rick DeNatale <rick.denatale@g=
mail.com said:
|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
| =A0 =A0def self.binding_of(b)
| =A0 =A0 =A0 =A0b.binding
| =A0 =A0end
|end
|
|A.binding_of("abc")
|
|might well return a binding with self =3D=3D 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 we=
ll.

--=20
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,150
Messages
2,570,853
Members
47,394
Latest member
Olekdev

Latest Threads

Top