Sha256: 0be2e14f6649134ff7bb417164a6ee985e1b040e634c4cc6f20e826e8f95bbe5

Contents?: true

Size: 1.3 KB

Versions: 26

Compression:

Stored size: 1.3 KB

Contents

module Steep
  module AST
    module Types
      class Literal
        attr_reader :location
        attr_reader :value

        def initialize(value:, location: nil)
          @location = location
          @value = value
        end

        def ==(other)
          other.is_a?(Literal) &&
            other.value == value
        end

        def hash
          self.class.hash
        end

        alias eql? ==

        def subst(s)
          self
        end

        def to_s
          value.inspect
        end

        include Helper::NoFreeVariables

        def level
          [0]
        end

        def with_location(new_location)
          self.class.new(location: new_location)
        end

        def back_type
          klass = case value
                  when Integer
                    Builtin::Integer
                  when String
                    Builtin::String
                  when Symbol
                    Builtin::Symbol
                  when true
                    Builtin::TrueClass
                  when false
                    Builtin::FalseClass
                  else
                    raise "Unexpected literal type: #{value.inspect}"
                  end

          Name::Instance.new(name: klass.module_name, args: [], location: location)
        end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
steep-0.48.0 lib/steep/ast/types/literal.rb
steep-0.47.1 lib/steep/ast/types/literal.rb
steep-0.47.0 lib/steep/ast/types/literal.rb
steep-0.46.0 lib/steep/ast/types/literal.rb
steep-0.45.0 lib/steep/ast/types/literal.rb
steep-0.44.1 lib/steep/ast/types/literal.rb
steep-0.44.0 lib/steep/ast/types/literal.rb
steep-0.43.1 lib/steep/ast/types/literal.rb
steep-0.43.0 lib/steep/ast/types/literal.rb
steep-0.42.0 lib/steep/ast/types/literal.rb
steep-0.41.0 lib/steep/ast/types/literal.rb
steep-0.40.0 lib/steep/ast/types/literal.rb
steep-0.39.0 lib/steep/ast/types/literal.rb
steep-0.38.0 lib/steep/ast/types/literal.rb
steep-0.37.0 lib/steep/ast/types/literal.rb
steep-0.36.0 lib/steep/ast/types/literal.rb
steep-0.35.0 lib/steep/ast/types/literal.rb
steep-0.34.0 lib/steep/ast/types/literal.rb
steep-0.33.0 lib/steep/ast/types/literal.rb
steep-0.32.0 lib/steep/ast/types/literal.rb