Class: Carbon::Tacky::Typed

Inherits:
Struct
  • Object
show all
Defined in:
lib/carbon/tacky/typed.rb

Constant Summary collapse

INT32 =
Carbon::Type("Carbon::Int32")
STRING =
Carbon::Type("Carbon::String")
FLOAT =
Carbon::Type("Carbon::Float")

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



6
7
8
# File 'lib/carbon/tacky/typed.rb', line 6

def type
  @type
end

#valueObject

Returns the value of attribute value

Returns:

  • (Object)

    the current value of value



6
7
8
# File 'lib/carbon/tacky/typed.rb', line 6

def value
  @value
end

Class Method Details

.from(value) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/carbon/tacky/typed.rb', line 11

def self.from(value)
  case value
  when Concrete::Type, Tacky::Typed then value
  when Tacky::Parameter             then new(value, value.type)
  when Tacky::Reference             then fail NotImplementedError
  when Tacky::Block                 then nil
  when ::Integer                    then new(value, INT32)
  when ::Float                      then new(value, FLOAT)
  when ::String, ::Symbol           then new(value, STRING)
  else fail ArgumentError, "Cannot guess type for #{value.class}"
  end
end