Sha256: 4683f281a5d06c7e3328d70d3f384b81e2ab49a631135c364af5436ec054a8c5

Contents?: true

Size: 572 Bytes

Versions: 2

Compression:

Stored size: 572 Bytes

Contents

# Add #result_with_hash for version less than 2.5
class ERB
  if RUBY_VERSION < "2.5"
    def result_with_hash(hash)
      b = new_toplevel(hash.keys)
      hash.each_pair do |key, value|
        b.local_variable_set(key, value)
      end
      result(b)
    end

    private

    # File lib/erb.rb, line 901
    def new_toplevel(vars = nil)
      b = TOPLEVEL_BINDING
      if vars
        vars = vars.select { |v| b.local_variable_defined?(v) }
        return b.eval("tap {|;#{vars.join(',')}| break binding}") unless vars.empty?
      end
      b.dup
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
active_notifier-0.4.2 lib/active_notifier/core_ext/erb/result_with_hash.rb
active_notifier-0.4.1 lib/active_notifier/core_ext/erb/result_with_hash.rb