Class: TRuby::IR::FunctionType

Inherits:
TypeNode show all
Defined in:
lib/t_ruby/ir.rb

Overview

Function/Proc type ((String, Integer) -> Boolean)

Instance Attribute Summary collapse

Attributes inherited from Node

#location, #metadata, #type_info

Instance Method Summary collapse

Methods inherited from Node

#accept, #children, #transform

Constructor Details

#initialize(return_type:, param_types: [], **opts) ⇒ FunctionType

Returns a new instance of FunctionType.



586
587
588
589
590
# File 'lib/t_ruby/ir.rb', line 586

def initialize(return_type:, param_types: [], **opts)
  super(**opts)
  @param_types = param_types
  @return_type = return_type
end

Instance Attribute Details

#param_typesObject

Returns the value of attribute param_types.



584
585
586
# File 'lib/t_ruby/ir.rb', line 584

def param_types
  @param_types
end

#return_typeObject

Returns the value of attribute return_type.



584
585
586
# File 'lib/t_ruby/ir.rb', line 584

def return_type
  @return_type
end

Instance Method Details

#to_rbsObject



592
593
594
595
# File 'lib/t_ruby/ir.rb', line 592

def to_rbs
  params = @param_types.map(&:to_rbs).join(", ")
  "^(#{params}) -> #{@return_type.to_rbs}"
end

#to_trbObject



597
598
599
600
# File 'lib/t_ruby/ir.rb', line 597

def to_trb
  params = @param_types.map(&:to_trb).join(", ")
  "(#{params}) -> #{@return_type.to_trb}"
end