class Combinder

see: djellemah.com/blog/2013/10/09/instance-eval-with-access-to-outside-scope/

Public Class Methods

new(obj, saved_binding) click to toggle source
# File lib/hash-mapper/combinder.rb, line 5
def initialize(obj, saved_binding)
  @obj, @saved_binding = obj, saved_binding
end

Public Instance Methods

__bound_self__() click to toggle source
# File lib/hash-mapper/combinder.rb, line 9
def __bound_self__
  @saved_binding.eval('self')
end
method_missing(meth, *args, &blk) click to toggle source
# File lib/hash-mapper/combinder.rb, line 13
def method_missing(meth, *args, &blk)
  # methods in dsl object are called in preference to self outside the block
  if @obj.respond_to?(meth)
    # dsl method, so call it
    @obj.send meth, *args, &blk
  else
    __bound_self__.send meth, *args, &blk
  end
end
respond_to_missing?(meth, _include_all) click to toggle source
# File lib/hash-mapper/combinder.rb, line 23
def respond_to_missing?(meth, _include_all)
  __bound_self__.respond_to?(meth) || @obj.respond_to?(meth)
end