class Contracts::MethodReference
MethodReference
represents original method reference that was decorated by contracts.ruby. Used for instance methods.
Attributes
Public Class Methods
Source
# File lib/contracts/method_reference.rb, line 11 def initialize(name, method) @name = name @method = method end
name - name of the method method - method object
Public Instance Methods
Source
# 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
Aliases original method to a special unique name, which is known only to this class. Usually done right before re-defining the method.
Source
# 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
Makes a method re-definition in proper way
Source
# File lib/contracts/method_reference.rb, line 17 def method_position Support.method_position(@method) end
Returns method_position
, delegates to Support.method_position
Source
# File lib/contracts/method_reference.rb, line 44 def send_to(this, *args, **kargs, &blk) this.send(aliased_name, *args, **kargs, &blk) end
Calls original method on specified ‘this` argument with specified arguments `args` and block `&blk`.
Private Instance Methods
Source
# File lib/contracts/method_reference.rb, line 72 def alias_target(this) this end
Returns alias target for instance methods, subject to be overriden in subclasses.
Source
# File lib/contracts/method_reference.rb, line 76 def aliased_name @_original_name ||= construct_unique_name end
Source
# File lib/contracts/method_reference.rb, line 80 def construct_unique_name :"__contracts_ruby_original_#{name}_#{Support.unique_id}" end
Source
# File lib/contracts/method_reference.rb, line 51 def make_private(this) original_name = name alias_target(this).class_eval { private original_name } end
Makes a method private
Source
# File lib/contracts/method_reference.rb, line 65 def make_protected(this) original_name = name alias_target(this).class_eval { protected original_name } end
Makes a method protected
Source
# File lib/contracts/method_reference.rb, line 56 def private?(this) this.private_instance_methods.map(&:to_sym).include?(name) end
Source
# File lib/contracts/method_reference.rb, line 60 def protected?(this) this.protected_instance_methods.map(&:to_sym).include?(name) end