From: rr.rosas@... Date: 2017-02-06T12:21:46+00:00 Subject: [ruby-core:79457] [CommonRuby Feature#8643] Add Binding.from_hash Issue #8643 has been updated by Rodrigo Rosenfeld Rosas. If #8631 was accepted, I think it could be okay to close this one as this is the only use-case for this I've needed so far. But before #8631 is accepted, this one would be also a good alternative... ---------------------------------------- Feature #8643: Add Binding.from_hash https://bugs.ruby-lang.org/issues/8643#change-62888 * Author: Rodrigo Rosenfeld Rosas * Status: Feedback * Priority: Normal * Assignee: Koichi Sasada * Target version: ---------------------------------------- `Binding.from_hash` would work like: ```ruby class Binding def self.from_hash(hash) OpenStruct.new(hash){ binding } end end ``` It would simplify things like: `ERB.new(IO.read 'template.erb').result Binding.from_hash(template_local: 'example')` Or if you need to `eval` some code in another process (JRuby, for instance) and need to pass some arguments to the `eval` code in a hash form. I didn't want to pollute `Hash` by adding `Hash#to_binding`. I believe `Binding.from_hash` is more appropriate. ---Files-------------------------------- feature-8643.pdf (19 KB) -- https://bugs.ruby-lang.org/ Unsubscribe: