Class: CopyMethod::CopiedMethod
- Inherits:
-
Module
- Object
- Module
- CopyMethod::CopiedMethod
- Defined in:
- lib/copy_method/copied_method.rb
Overview
Preserve constant lookups in copied methods.
Instance Attribute Summary collapse
- #method_name ⇒ Symbol readonly
- #origin ⇒ Symbol readonly
-
#singleton ⇒ Object
(also: #singleton?)
readonly
Returns the value of attribute singleton.
Instance Method Summary collapse
-
#initialize(origin, method_name, singleton: false) ⇒ CopiedMethod
constructor
A new instance of CopiedMethod.
- #inspect ⇒ Object
Constructor Details
#initialize(origin, method_name, singleton: false) ⇒ CopiedMethod
Returns a new instance of CopiedMethod.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/copy_method/copied_method.rb', line 18 def initialize(origin, method_name, singleton: false) @method_name = method_name @origin = origin.to_s.to_sym @singleton = singleton class_eval <<-RUBY, __FILE__, __LINE__ + 1 def const_missing(const_name) caller_method = caller_locations(1,1)[0].label super rescue NameError => e origin = ::#{origin} if caller_method == #{method_name.to_s.inspect} && origin.const_defined?(const_name) origin.const_get const_name else raise e end end RUBY end |
Instance Attribute Details
#method_name ⇒ Symbol (readonly)
6 7 8 |
# File 'lib/copy_method/copied_method.rb', line 6 def method_name @method_name end |
#origin ⇒ Symbol (readonly)
10 11 12 |
# File 'lib/copy_method/copied_method.rb', line 10 def origin @origin end |
#singleton ⇒ Object (readonly) Also known as: singleton?
Returns the value of attribute singleton.
12 13 14 |
# File 'lib/copy_method/copied_method.rb', line 12 def singleton @singleton end |
Instance Method Details
#inspect ⇒ Object
40 41 42 |
# File 'lib/copy_method/copied_method.rb', line 40 def inspect "CopyMethod::CopiedMethod(#{origin}#{method_symbol}#{method_name})" end |