Class: Contracts::MethodHandler
- Inherits:
-
Object
- Object
- Contracts::MethodHandler
- Defined in:
- lib/contracts-ruby2/lib/contracts/method_handler.rb,
lib/contracts-ruby3/lib/contracts/method_handler.rb
Overview
Handles class and instance methods addition Represents single such method
Constant Summary collapse
- METHOD_REFERENCE_FACTORY =
{ :class_methods => SingletonMethodReference, :instance_methods => MethodReference, }
- RAW_METHOD_STRATEGY =
{ :class_methods => lambda { |target, name| target.method(name) }, :instance_methods => lambda { |target, name| target.instance_method(name) }, }
Instance Method Summary collapse
-
#handle ⇒ Object
Handles method addition.
-
#initialize(method_name, is_class_method, target) ⇒ MethodHandler
constructor
Creates new instance of MethodHandler.
Constructor Details
#initialize(method_name, is_class_method, target) ⇒ MethodHandler
Creates new instance of MethodHandler
20 21 22 23 24 |
# File 'lib/contracts-ruby2/lib/contracts/method_handler.rb', line 20 def initialize(method_name, is_class_method, target) @method_name = method_name @is_class_method = is_class_method @target = target end |
Instance Method Details
#handle ⇒ Object
Handles method addition
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/contracts-ruby2/lib/contracts/method_handler.rb', line 27 def handle return unless engine? return if decorators.empty? validate_decorators! validate_pattern_matching! engine.add_method_decorator(method_type, method_name, decorator) mark_pattern_matching_decorators method_reference.make_alias(target) redefine_method end |