RCR 251: Add Binding#eval
submitted by batkins on Mon May 10 2004 03:56:03 PM -0700
Status: accepted
Abstract
Allows Ruby programmers to eval code within a Binding object in a more object-oriented, Rubyesque fashion.
Problem
In order to evaluate a bit of code within Binding b, you call Kernel#eval, like so: eval "myvar = 34", b This sets myvar to 32 within b. However, this isn't very object-oriented.
Proposal
I propose to create a Binding#eval method and deprecate and/or remove the binding argument from Kernel#eval. This will allow the above code to be written as: b.eval "myvar = 34"
Analysis
Makes eval'ing within a Binding more fitting with the Ruby Way.
Implementation
class Binding def eval str Kernel.eval str, self end end There should also be a block version.
Back to RCRchive.
RCR Submission page and RCRchive powered by Ruby, Apache, RuWiki (modified), and RubLog