From: "rosenfeld (Rodrigo Rosenfeld Rosas)" Date: 2013-08-12T23:27:11+09:00 Subject: [ruby-core:56579] [CommonRuby - Feature #8643] Add Binding.from_hash Issue #8643 has been updated by rosenfeld (Rodrigo Rosenfeld Rosas). Koichi then replied with: I'm not sure what methods and variables are leaks. For example, only "make_binding" mathod is leaked. ## def make_binding(hash) __b = binding hash.each{|k, v| __b.local_variable_set(k, v) } __b end created_binding = make_binding(a: 1, b: 2) ... ---------------------------------------- Feature #8643: Add Binding.from_hash https://bugs.ruby-lang.org/issues/8643#change-41114 Author: rosenfeld (Rodrigo Rosenfeld Rosas) Status: Open Priority: Normal Assignee: ko1 (Koichi Sasada) Category: Target version: Binding.from_hash would work like: 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. -- http://bugs.ruby-lang.org/