Class: EacRubyUtils::ActsAsInstanceMethod

Inherits:
Object
  • Object
show all
Defined in:
lib/eac_ruby_utils/acts_as_instance_method.rb

Direct Known Subclasses

MethodClass::Setup

Instance Method Summary collapse

Instance Method Details

#default_sender_moduleModule

Returns:



30
31
32
# File 'lib/eac_ruby_utils/acts_as_instance_method.rb', line 30

def default_sender_module
  method_class.module_parent
end

#method_nameString

Returns:



25
26
27
# File 'lib/eac_ruby_utils/acts_as_instance_method.rb', line 25

def method_name
  method_class.name.demodulize.underscore.variableize
end

#setup(sender_module = nil) ⇒ self

Parameters:

  • sender_module (Module, nil) (defaults to: nil)

Returns:

  • (self)


14
15
16
17
18
19
20
21
22
# File 'lib/eac_ruby_utils/acts_as_instance_method.rb', line 14

def setup(sender_module = nil)
  sender_module ||= default_sender_module
  the_setup = self
  sender_module.define_method(method_name) do |*args, &block|
    the_setup.method_class.new(self, *args, &block).result
  end

  self
end