Module: Malt::Conversions::Binding

Extended by:
Binding
Included in:
Binding
Defined in:
lib/malt/conversions.rb

Instance Method Summary collapse

Instance Method Details

#to_binding(binding) ⇒ Object


9
10
11
# File 'lib/malt/conversions.rb', line 9

def to_binding(binding)
  binding
end

#to_hash(binding) ⇒ Object


14
15
16
# File 'lib/malt/conversions.rb', line 14

def to_hash(binding)
  Hash.new{ |h,k| h[k] = binding.eval(k) }
end

#to_object(binding) ⇒ Object


19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/malt/conversions.rb', line 19

def to_object(binding)
  obj = binding.eval("self")

  vars  = binding.eval("local_variables")
  vals  = binding.eval("[#{vars.join(',')}]")
  data  = Hash[*vars.zip(vals).flatten]

  adhoc = (class << obj; self; end)
  data.each do |name,value|
    adhoc.__send__(:define_method, name){ value }
  end

  obj
end