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
-
#send_to(this, *args, &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
9 10 11 12 |
# File 'lib/contracts/method_reference.rb', line 9 def initialize(name, method) @name = name @method = method end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/contracts/method_reference.rb', line 5 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.
30 31 32 33 34 35 36 37 |
# File 'lib/contracts/method_reference.rb', line 30 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
19 20 21 22 23 24 25 |
# File 'lib/contracts/method_reference.rb', line 19 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
14 15 16 |
# File 'lib/contracts/method_reference.rb', line 14 def method_position Support.method_position(@method) end |
#send_to(this, *args, &blk) ⇒ Object
Calls original method on specified ‘this` argument with specified arguments `args` and block `&blk`.
41 42 43 |
# File 'lib/contracts/method_reference.rb', line 41 def send_to(this, *args, &blk) this.send(aliased_name, *args, &blk) end |