Class: EacRubyUtils::Ruby::OnReplaceObjects::ReplaceInstanceMethod

Inherits:
Object
  • Object
show all
Defined in:
lib/eac_ruby_utils/ruby/on_replace_objects/replace_instance_method.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(a_module, method_name, &method_new_block) ⇒ ReplaceInstanceMethod

Returns a new instance of ReplaceInstanceMethod.



12
13
14
15
16
# File 'lib/eac_ruby_utils/ruby/on_replace_objects/replace_instance_method.rb', line 12

def initialize(a_module, method_name, &method_new_block)
  @a_module = a_module
  @original_method = a_module.instance_method(method_name)
  @method_new_block = method_new_block
end

Instance Attribute Details

#a_moduleObject (readonly)

Returns the value of attribute a_module.



10
11
12
# File 'lib/eac_ruby_utils/ruby/on_replace_objects/replace_instance_method.rb', line 10

def a_module
  @a_module
end

#method_new_blockObject (readonly)

Returns the value of attribute method_new_block.



10
11
12
# File 'lib/eac_ruby_utils/ruby/on_replace_objects/replace_instance_method.rb', line 10

def method_new_block
  @method_new_block
end

#original_methodObject (readonly)

Returns the value of attribute original_method.



10
11
12
# File 'lib/eac_ruby_utils/ruby/on_replace_objects/replace_instance_method.rb', line 10

def original_method
  @original_method
end

Instance Method Details

#applyObject



18
19
20
21
22
# File 'lib/eac_ruby_utils/ruby/on_replace_objects/replace_instance_method.rb', line 18

def apply
  a_module.define_method(method_name, &method_new_block)

  self
end

#method_nameObject



24
25
26
# File 'lib/eac_ruby_utils/ruby/on_replace_objects/replace_instance_method.rb', line 24

def method_name
  original_method.name
end

#restoreObject



28
29
30
31
32
# File 'lib/eac_ruby_utils/ruby/on_replace_objects/replace_instance_method.rb', line 28

def restore
  a_module.define_method(method_name, original_method)

  self
end