Class: Contracts::MethodReference
- Inherits:
-
Object
- Object
- Contracts::MethodReference
- Defined in:
- lib/contracts/method_reference.rb
Overview
MethodReference represents original method reference that was decorated by contracts.ruby. Used for instance methods.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name, method) ⇒ MethodReference
constructor
name - name of the method method - method object.
-
#make_alias(this) ⇒ Object
Aliases original method to a special unique name, which is known only to this class.
-
#make_definition(this, &blk) ⇒ Object
Makes a method re-definition in proper way.
-
#method_position ⇒ Object
Returns method_position, delegates to Support.method_position.
-
#send_to(this, *args, **kargs, &blk) ⇒ Object
Calls original method on specified ‘this` argument with specified arguments `args` and block `&blk`.
Constructor Details
#initialize(name, method) ⇒ MethodReference
name - name of the method method - method object
11 12 13 14 |
# File 'lib/contracts/method_reference.rb', line 11 def initialize(name, method) @name = name @method = method end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/contracts/method_reference.rb', line 7 def name @name end |
Instance Method Details
#make_alias(this) ⇒ Object
Aliases original method to a special unique name, which is known only to this class. Usually done right before re-defining the method.
33 34 35 36 37 38 39 40 |
# File 'lib/contracts/method_reference.rb', line 33 def make_alias(this) _aliased_name = aliased_name original_name = name alias_target(this).class_eval do alias_method _aliased_name, original_name end end |
#make_definition(this, &blk) ⇒ Object
Makes a method re-definition in proper way
22 23 24 25 26 27 28 |
# File 'lib/contracts/method_reference.rb', line 22 def make_definition(this, &blk) is_private = private?(this) is_protected = protected?(this) alias_target(this).send(:define_method, name, &blk) make_private(this) if is_private make_protected(this) if is_protected end |
#method_position ⇒ Object
Returns method_position, delegates to Support.method_position
17 18 19 |
# File 'lib/contracts/method_reference.rb', line 17 def method_position Support.method_position(@method) end |
#send_to(this, *args, **kargs, &blk) ⇒ Object
Calls original method on specified ‘this` argument with specified arguments `args` and block `&blk`.
44 45 46 |
# File 'lib/contracts/method_reference.rb', line 44 def send_to(this, *args, **kargs, &blk) this.send(aliased_name, *args, **kargs, &blk) end |