Module: Gemmy::Patches::ObjectPatch::InstanceMethods::HierarchicalSend

Defined in:
lib/gemmy/patches/object_patch.rb

Instance Method Summary collapse

Instance Method Details

#hierarchical_send(method_name, *args, &block) ⇒ Object

c.new.a #=> 1



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/gemmy/patches/object_patch.rb', line 153

def hierarchical_send(method_name, *args, &block)
  method_name = method_name.to_s if RUBY_VERSION < '1.9'
  this = self
  self.class.hierarchically do |anc|
    ## is there really no better way to check for the method?
    if anc.instance_methods(false).include?(method_name) or
         anc.public_instance_methods(false).include?(method_name) or
         anc.private_instance_methods(false).include?(method_name) or
         anc.protected_instance_methods(false).include?(method_name)
      im = anc.instance_method(method_name)
      ##im.arity == 0 ? im.bind(this).call(&block) : im.bind(this).call(*args, &block)
      im.bind(this).call(*args, &block)
    end
  end
end