Class: Types::Method
Overview
Represents a method type attached to a receiver type.
“‘ruby type = Types::Method(Types::String, Types::Integer, returns: Types::String) type.to_s # => “Method(String, Integer, returns: String)” “`
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
Parses the input as a method or proc.
- #to_rbs ⇒ Object
- #to_s ⇒ Object
Methods included from Generic
Constructor Details
#initialize(receiver_type, argument_types, return_type) ⇒ Method
Returns a new instance of Method.
22 23 24 25 26 |
# File 'lib/types/method.rb', line 22 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.
31 32 33 |
# File 'lib/types/method.rb', line 31 def argument_types @argument_types end |
#receiver_type ⇒ Object (readonly)
Returns the value of attribute receiver_type.
29 30 31 |
# File 'lib/types/method.rb', line 29 def receiver_type @receiver_type end |
#return_type ⇒ Object (readonly)
Returns the value of attribute return_type.
33 34 35 |
# File 'lib/types/method.rb', line 33 def return_type @return_type end |
Instance Method Details
#parse(input) ⇒ Object
Parses the input as a method or proc.
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/types/method.rb', line 68 def parse(input) case input when ::String receiver_type.resolve.instance_method(input) when ::Proc input else raise ArgumentError, "Cannot coerce #{input.inspect} into Method!" end end |
#to_rbs ⇒ Object
60 61 62 |
# File 'lib/types/method.rb', line 60 def to_rbs "Method" end |
#to_s ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/types/method.rb', line 41 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 |