Class: Steep::AST::Types::Var

Inherits:
Object
  • Object
show all
Defined in:
lib/steep/ast/types/var.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, location: nil) ⇒ Var

Returns a new instance of Var.



8
9
10
11
# File 'lib/steep/ast/types/var.rb', line 8

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

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



6
7
8
# File 'lib/steep/ast/types/var.rb', line 6

def location
  @location
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/steep/ast/types/var.rb', line 5

def name
  @name
end

Class Method Details

.fresh(name) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/steep/ast/types/var.rb', line 24

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

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

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

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



13
14
15
16
# File 'lib/steep/ast/types/var.rb', line 13

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

#free_variablesObject



47
48
49
# File 'lib/steep/ast/types/var.rb', line 47

def free_variables
  Set.new([name])
end

#hashObject



18
19
20
# File 'lib/steep/ast/types/var.rb', line 18

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

#levelObject



51
52
53
# File 'lib/steep/ast/types/var.rb', line 51

def level
  [0]
end

#subst(s) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/steep/ast/types/var.rb', line 39

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

#to_sObject



35
36
37
# File 'lib/steep/ast/types/var.rb', line 35

def to_s
  "'#{name}"
end

#with_location(new_location) ⇒ Object



55
56
57
# File 'lib/steep/ast/types/var.rb', line 55

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