Class: TRuby::IR::NullableType

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

Overview

Nullable type (String?)

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(inner_type:, **opts) ⇒ NullableType



643
644
645
646
# File 'lib/t_ruby/ir.rb', line 643

def initialize(inner_type:, **opts)
  super(**opts)
  @inner_type = inner_type
end

Instance Attribute Details

#inner_typeObject

Returns the value of attribute inner_type.



641
642
643
# File 'lib/t_ruby/ir.rb', line 641

def inner_type
  @inner_type
end

Instance Method Details

#to_rbsObject



648
649
650
651
652
653
654
655
656
# File 'lib/t_ruby/ir.rb', line 648

def to_rbs
  inner_rbs = @inner_type.to_rbs
  # Simple types can use ? suffix, complex types need (Type | nil) form
  if @inner_type.is_a?(SimpleType)
    "#{inner_rbs}?"
  else
    "(#{inner_rbs} | nil)"
  end
end

#to_trbObject



658
659
660
# File 'lib/t_ruby/ir.rb', line 658

def to_trb
  "#{@inner_type.to_trb}?"
end