Class: Combinder

Inherits:
BasicObject
Defined in:
lib/hash-mapper/combinder.rb

Overview

Instance Method Summary collapse

Constructor Details

#initialize(obj, saved_binding) ⇒ Combinder

Returns a new instance of Combinder.



5
6
7
# File 'lib/hash-mapper/combinder.rb', line 5

def initialize(obj, saved_binding)
  @obj, @saved_binding = obj, saved_binding
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &blk) ⇒ Object



13
14
15
16
17
18
19
20
21
# 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

Instance Method Details

#__bound_self__Object



9
10
11
# File 'lib/hash-mapper/combinder.rb', line 9

def __bound_self__
  @saved_binding.eval('self')
end

#respond_to_missing?(meth, _include_all) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# 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