Class: Steep::AST::Types::Var
- Inherits:
-
Object
- Object
- Steep::AST::Types::Var
- Defined in:
- lib/steep/ast/types/var.rb
Instance Attribute Summary collapse
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #free_variables ⇒ Object
- #hash ⇒ Object
-
#initialize(name:, location: nil) ⇒ Var
constructor
A new instance of Var.
- #level ⇒ Object
- #subst(s) ⇒ Object
- #to_s ⇒ Object
- #with_location(new_location) ⇒ Object
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
#location ⇒ Object (readonly)
Returns the value of attribute location.
6 7 8 |
# File 'lib/steep/ast/types/var.rb', line 6 def location @location end |
#name ⇒ Object (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_variables ⇒ Object
47 48 49 |
# File 'lib/steep/ast/types/var.rb', line 47 def free_variables Set.new([name]) end |
#hash ⇒ Object
18 19 20 |
# File 'lib/steep/ast/types/var.rb', line 18 def hash self.class.hash ^ name.hash end |
#level ⇒ Object
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_s ⇒ Object
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 |