Module: Loverload::ClassMethods

Defined in:
lib/loverload.rb

Instance Method Summary collapse

Instance Method Details

#def_overload(method_name_or_class, method_name = NULL, &with_params_block) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/loverload.rb', line 13

def def_overload(method_name_or_class, method_name = NULL, &with_params_block)
  if method_name_or_class.is_a?(Class) && method_name != NULL
    method = Method.new(method_name_or_class, method_name, &with_params_block)

    define_singleton_method method_name do |*args, &block|
      method.overload(method_name_or_class, *args, &block)
    end
  else
    method = Method.new(self, method_name_or_class, &with_params_block)

    define_method method_name_or_class do |*args, &block|
      method.overload(self, *args, &block)
    end
  end
end