Class: Types::Method
Overview
A method type attached to a receiver type.
Instance Attribute Summary collapse
-
#argument_types ⇒ Object
readonly
Returns the value of attribute argument_types.
-
#receiver_type ⇒ Object
readonly
Returns the value of attribute receiver_type.
-
#return_type ⇒ Object
readonly
Returns the value of attribute return_type.
Instance Method Summary collapse
- #composite? ⇒ Boolean
-
#initialize(receiver_type, argument_types, return_type) ⇒ Method
constructor
A new instance of Method.
- #parse(input) ⇒ Object
- #to_s ⇒ Object
Methods included from Generic
Constructor Details
#initialize(receiver_type, argument_types, return_type) ⇒ Method
Returns a new instance of Method.
30 31 32 33 34 |
# File 'lib/types/method.rb', line 30 def initialize(receiver_type, argument_types, return_type) @receiver_type = receiver_type @argument_types = argument_types @return_type = return_type end |
Instance Attribute Details
#argument_types ⇒ Object (readonly)
Returns the value of attribute argument_types.
37 38 39 |
# File 'lib/types/method.rb', line 37 def argument_types @argument_types end |
#receiver_type ⇒ Object (readonly)
Returns the value of attribute receiver_type.
36 37 38 |
# File 'lib/types/method.rb', line 36 def receiver_type @receiver_type end |
#return_type ⇒ Object (readonly)
Returns the value of attribute return_type.
38 39 40 |
# File 'lib/types/method.rb', line 38 def return_type @return_type end |
Instance Method Details
#parse(input) ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/types/method.rb', line 62 def parse(input) case input when ::String receiver_type.instance_method(input) when ::Proc input else raise ArgumentError, "Cannot coerce #{input.inpsect} into Method!" end end |
#to_s ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/types/method.rb', line 44 def to_s buffer = ::String.new if @argument_types&.any? buffer << "Method(#{@receiver_type}, #{@argument_types.join(', ')}" else buffer << "Method(#{@receiver_type}, " end if @return_type buffer << "returns: #{@return_type})" else buffer << ")" end return buffer end |