Class: RBS::Types::Variable
- Inherits:
-
Object
- Object
- RBS::Types::Variable
- Includes:
- EmptyEachType, NoTypeName
- Defined in:
- lib/rbs/types.rb
Constant Summary collapse
- @@count =
0
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(set = Set.new) ⇒ Object
- #hash ⇒ Object
-
#initialize(name:, location:) ⇒ Variable
constructor
A new instance of Variable.
- #sub(s) ⇒ Object
- #to_json(state = _ = nil) ⇒ Object
- #to_s(level = 0) ⇒ Object
Methods included from EmptyEachType
Methods included from NoTypeName
Constructor Details
#initialize(name:, location:) ⇒ Variable
Returns a new instance of Variable.
114 115 116 117 |
# File 'lib/rbs/types.rb', line 114 def initialize(name:, location:) @name = name @location = location end |
Instance Attribute Details
#location ⇒ Object (readonly)
Returns the value of attribute location.
110 111 112 |
# File 'lib/rbs/types.rb', line 110 def location @location end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
109 110 111 |
# File 'lib/rbs/types.rb', line 109 def name @name end |
Class Method Details
.build(v) ⇒ Object
143 144 145 146 147 148 149 150 |
# File 'lib/rbs/types.rb', line 143 def self.build(v) case v when Symbol new(name: v, location: nil) when Array v.map {|x| new(name: x, location: nil) } end end |
.fresh(v = :T) ⇒ Object
153 154 155 156 |
# File 'lib/rbs/types.rb', line 153 def self.fresh(v = :T) @@count = @@count + 1 new(name: :"#{v}@#{@@count}", location: nil) end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
119 120 121 |
# File 'lib/rbs/types.rb', line 119 def ==(other) other.is_a?(Variable) && other.name == name end |
#free_variables(set = Set.new) ⇒ Object
129 130 131 132 133 |
# File 'lib/rbs/types.rb', line 129 def free_variables(set = Set.new) set.tap do set << name end end |
#hash ⇒ Object
125 126 127 |
# File 'lib/rbs/types.rb', line 125 def hash self.class.hash ^ name.hash end |
#sub(s) ⇒ Object
139 140 141 |
# File 'lib/rbs/types.rb', line 139 def sub(s) s.apply(self) end |
#to_json(state = _ = nil) ⇒ Object
135 136 137 |
# File 'lib/rbs/types.rb', line 135 def to_json(state = _ = nil) { class: :variable, name: name, location: location }.to_json(state) end |
#to_s(level = 0) ⇒ Object
158 159 160 |
# File 'lib/rbs/types.rb', line 158 def to_s(level = 0) name.to_s end |