For meta-programming purposes I think there needs to be a way to get a BasicObject's binding.
#2 [ruby-core:39695] Updated by Thomas Sawyer almost 5 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.
#3 Updated by George Koehler over 4 years ago
I can get a Binding from a BasicObject like so:
class Cow < BasicObject
Moo = "Moooo!"
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.