Class: Inferior::Core::Method
- Inherits:
-
Object
- Object
- Inferior::Core::Method
- Defined in:
- lib/inferior/core/method.rb
Constant Summary collapse
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
Class Method Summary collapse
Instance Method Summary collapse
- #definition ⇒ Object
- #eql?(other) ⇒ Boolean
-
#initialize(name:, parameters:) ⇒ Method
constructor
A new instance of Method.
- #verify_class!(klass) ⇒ Object
Constructor Details
#initialize(name:, parameters:) ⇒ Method
Returns a new instance of Method.
47 48 49 50 |
# File 'lib/inferior/core/method.rb', line 47 def initialize(name:, parameters:) @name = name @parameters = parameters end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
45 46 47 |
# File 'lib/inferior/core/method.rb', line 45 def name @name end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
45 46 47 |
# File 'lib/inferior/core/method.rb', line 45 def parameters @parameters end |
Class Method Details
.build!(name:, parameters:) ⇒ Object
17 18 19 20 21 |
# File 'lib/inferior/core/method.rb', line 17 def build!(name:, parameters:) validate_name!(name) validate_parameters!(parameters) new(name: name, parameters: parameters) end |
.parse!(method) ⇒ Object
23 24 25 26 |
# File 'lib/inferior/core/method.rb', line 23 def parse!(method) parameters = parse_parameters!(method) build!(parameters: parameters, name: method.name) end |
Instance Method Details
#definition ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/inferior/core/method.rb', line 84 def definition parameters_definition = parameters.any? ? "(#{parameters.map(&:definition).join(", ")})" : nil <<~RUBY.strip def #{name}#{parameters_definition} end RUBY end |
#eql?(other) ⇒ Boolean
52 53 54 55 56 57 58 59 |
# File 'lib/inferior/core/method.rb', line 52 def eql?(other) return false unless name.eql?(other.name) return false unless parameters.size.eql?(other.parameters.size) parameters.each_with_index.all? do |parameter, index| parameter.eql?(other.parameters[index]) end end |
#verify_class!(klass) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/inferior/core/method.rb', line 61 def verify_class!(klass) unless klass.method_defined?(name) raise VerificationError, <<~ERROR.strip #{klass.name} should implement a method with the following signature: #{definition} ERROR end actual = self.class.parse!(klass.instance_method(name)) return if eql?(actual) raise VerificationError, <<~ERROR #{klass.name} should implement a method with the following signature: #{definition} but the actual signature is the following: #{actual.definition} ERROR end |