Note that there are some explanatory texts on larger screens.

plurals
  1. POIs 'eval' the only way to interact with binding objects in Ruby?
    primarykey
    data
    text
    <p>I'm rather new to Ruby, and so far, figuring out how to use <a href="http://ruby-doc.org/core/classes/Binding.html" rel="noreferrer">"binding" objects</a> is one of the biggest pain points for me. If I'm reading the documentation correctly, they're almost entirely opaque. To access the scope inside the binding object, you have to have a string of Ruby code and <a href="http://ruby-doc.org/core/classes/Kernel.html#M005922" rel="noreferrer">eval</a> it using the binding.</p> <p>Maybe I'm just a purist from a different school, but I'm allergic to string-based 'eval' constructs, generally speaking. Is there any way to do any of the following, securely and in the general case, given a binding object:</p> <ol> <li>List the identifiers in scope in the context the binding represents, or retrieve a hash of the contents.</li> <li>Set the value of a local variable in the binding equal to that of some local variable in an external context. Ideally, this should work generally, even if the value is an object reference, file handle, or some other complex entity.</li> <li>(extension 2:) Given a hash, set locals in the binding for each entry.</li> <li>Better yet, given a hash build a binding with <em>only</em> the basic language constructs and the names in the hash in scope.</li> </ol> <p>Basically, I want to know which of those is possible and how to accomplish the ones that are. I imagine that the solutions for each will be fairly closely related, which is why I'm putting all of this in a single question.</p> <p>Alternatively, is there any way to eval code that's already been parsed in the context of a binding, similar to Perl's eval BLOCK syntax?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload