Project

General

Profile

Actions

Feature #5360

closed

BasicObject#binding

Added by trans (Thomas Sawyer) over 12 years ago. Updated about 6 years ago.

Status:
Feedback
Assignee:
-
Target version:
-
[ruby-core:39690]

Description

For meta-programming purposes I think there needs to be a way to get a BasicObject's binding.

Updated by nobu (Nobuyoshi Nakada) over 12 years ago

  • Status changed from Open to Feedback

Can you elaborate?

Updated by trans (Thomas Sawyer) over 12 years ago

Sure. I think the most obvious usecase is with ERB. If I want to strictly control the available interface to an ERB template a subclass of BasicObject is an ideal way to do. But ERB's result method takes a binding. So that's one specific case I've come across, and I am certain there are others given that both BasicObject and binding are very useful devices in the context of meta-programming.

Actions #3

Updated by kernigh (George Koehler) over 12 years ago

I can get a Binding from a BasicObject like so:

class Cow < BasicObject
Moo = "Moooo!"
def binding
::Kernel.binding
end
end

b = Cow.new.binding
p eval("Moo", b) # => "Moooo!"
p eval("String", b) # raises NameError

This uses the syntax "::Kernel" to access a global constant.

Updated by trans (Thomas Sawyer) over 12 years ago

On Sep 27, 3:51 pm, George Koehler wrote:

Issue #5360 has been updated by George Koehler.

I can get a Binding from a BasicObject like so:

 class Cow < BasicObject
   Moo

Updated by mame (Yusuke Endoh) over 11 years ago

  • Target version set to 2.6
Actions #6

Updated by naruse (Yui NARUSE) about 6 years ago

  • Target version deleted (2.6)
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0