Class: Types::Block
Overview
Represents a block (Proc) type with argument and return types.
“‘ruby type = Types::Block(Types::String, Types::Integer, returns: Types::String) type.to_s # => “Block(String, Integer, returns: String)” “`
Instance Attribute Summary collapse
-
#argument_types ⇒ Object
readonly
Returns the value of attribute argument_types.
-
#return_type ⇒ Object
readonly
Returns the value of attribute return_type.
Instance Method Summary collapse
- #composite? ⇒ Boolean
-
#initialize(argument_types, return_type) ⇒ Block
constructor
A new instance of Block.
- #to_rbs ⇒ Object
- #to_s ⇒ Object
Methods included from Generic
Constructor Details
#initialize(argument_types, return_type) ⇒ Block
Returns a new instance of Block.
21 22 23 24 |
# File 'lib/types/block.rb', line 21 def initialize(argument_types, return_type) @argument_types = argument_types @return_type = return_type end |
Instance Attribute Details
#argument_types ⇒ Object (readonly)
Returns the value of attribute argument_types.
27 28 29 |
# File 'lib/types/block.rb', line 27 def argument_types @argument_types end |
#return_type ⇒ Object (readonly)
Returns the value of attribute return_type.
30 31 32 |
# File 'lib/types/block.rb', line 30 def return_type @return_type end |
Instance Method Details
#to_rbs ⇒ Object
47 48 49 50 51 52 |
# File 'lib/types/block.rb', line 47 def to_rbs argument_types = @argument_types.map(&:to_rbs).join(", ") return_type = @return_type ? @return_type.to_rbs : "void" return "^(#{argument_types}) -> #{return_type}" end |
#to_s ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/types/block.rb', line 38 def to_s if @return_type "Block(#{@argument_types.join(', ')}, returns: #{@return_type})" else "Block(#{@argument_types.join(', ')})" end end |