module DR::Eruby::BindingHelper
Constants
- BLANK_OBJECT
- EMPTY_BINDING
empty binding (at first) that stays the same and can be shared
Public Instance Methods
add_variables(variables, _binding=empty_binding)
click to toggle source
add variables values to a binding; variables is a Hash
# File lib/dr/base/eruby.rb, line 18 def add_variables(variables, _binding=empty_binding) eval variables.collect{|k,v| "#{k} = variables[#{k.inspect}]; "}.join, _binding _binding end
empty_binding()
click to toggle source
complement TOPLEVEL_BINDING
# File lib/dr/base/eruby.rb, line 6 def empty_binding #wraps into anonymous module so that 'def foo' do not pollute namespace Module.new do #regenerate a new binding return binding end end
local_extraction(local_keys, context_name: '_context')
click to toggle source
From Tilt/template.rb return a string extracting local_keys from a hash named _context
# File lib/dr/base/eruby.rb, line 25 def local_extraction(local_keys, context_name: '_context') local_keys.map do |k| if k.to_s =~ /\A[a-z_][a-zA-Z_0-9]*\z/ "#{k} = #{context_name}[#{k.inspect}]" else raise "invalid locals key: #{k.inspect} (keys must be variable names)" end end.join("\n")+"\n" end