Sha256: 7391257337f468db1268dc8d864d42ddb2e66e0414748bd1a2e12353b8300237

Contents?: true

Size: 1.03 KB

Versions: 18

Compression:

Stored size: 1.03 KB

Contents

module Steep
  module AST
    module Types
      class Var
        attr_reader :name
        attr_reader :location

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

        def ==(other)
          other.is_a?(Var) &&
            other.name == name
        end

        def hash
          self.class.hash ^ name.hash
        end

        alias eql? ==

        def self.fresh(name)
          @mutex ||= Mutex.new

          @mutex.synchronize do
            @max ||= 0
            @max += 1

            new(name: :"#{name}(#{@max})")
          end
        end

        def to_s
          name.to_s
        end

        def subst(s)
          if s.key?(name)
            s[name]
          else
            self
          end
        end

        def free_variables
          Set.new([name])
        end

        def level
          [0]
        end

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

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
steep-0.25.0 lib/steep/ast/types/var.rb
steep-0.24.0 lib/steep/ast/types/var.rb
steep-0.23.0 lib/steep/ast/types/var.rb
steep-0.22.0 lib/steep/ast/types/var.rb
steep-0.21.0 lib/steep/ast/types/var.rb
steep-0.20.0 lib/steep/ast/types/var.rb
steep-0.19.0 lib/steep/ast/types/var.rb
steep-0.18.0 lib/steep/ast/types/var.rb
steep-0.17.1 lib/steep/ast/types/var.rb
steep-0.17.0 lib/steep/ast/types/var.rb
steep-0.16.3 lib/steep/ast/types/var.rb
steep-0.16.2 lib/steep/ast/types/var.rb
steep-0.16.1 lib/steep/ast/types/var.rb
steep-0.16.0 lib/steep/ast/types/var.rb
steep-0.15.0 lib/steep/ast/types/var.rb
steep-0.14.0 lib/steep/ast/types/var.rb
steep-0.13.0 lib/steep/ast/types/var.rb
steep-0.12.0 lib/steep/ast/types/var.rb