Project

General

Profile

Actions

Feature #8643

closed

Add Binding.from_hash

Added by rosenfeld (Rodrigo Rosenfeld Rosas) almost 11 years ago. Updated over 2 years ago.

Status:
Rejected
Target version:
-
[ruby-core:56041]

Description

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.


Files

feature-8643.pdf (19 KB) feature-8643.pdf Proposal slide rosenfeld (Rodrigo Rosenfeld Rosas), 06/26/2014 12:40 PM

Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #8631: Add a new method to ERB to allow assigning the local variables from a hashClosedk0kubun (Takashi Kokubun)Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0