Class: Types::Block

Inherits:
Object
  • Object
show all
Includes:
Generic
Defined in:
lib/types/block.rb

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

Instance Method Summary collapse

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_typesObject (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_typeObject (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

#composite?Boolean

Returns:



33
34
35
# File 'lib/types/block.rb', line 33

def composite?
	true
end

#to_rbsObject



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_sObject



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