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
- #has_classish_type? ⇒ Boolean
- #has_self_type? ⇒ Boolean
- #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
- #with_nonreturn_void? ⇒ Boolean
Methods included from EmptyEachType
Methods included from NoTypeName
Constructor Details
#initialize(name:, location:) ⇒ Variable
139 140 141 142 |
# File 'lib/rbs/types.rb', line 139 def initialize(name:, location:) @name = name @location = location end |
Instance Attribute Details
#location ⇒ Object (readonly)
Returns the value of attribute location.
135 136 137 |
# File 'lib/rbs/types.rb', line 135 def location @location end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
134 135 136 |
# File 'lib/rbs/types.rb', line 134 def name @name end |
Class Method Details
.build(v) ⇒ Object
168 169 170 171 172 173 174 175 |
# File 'lib/rbs/types.rb', line 168 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
178 179 180 181 |
# File 'lib/rbs/types.rb', line 178 def self.fresh(v = :T) @@count = @@count + 1 new(name: :"#{v}@#{@@count}", location: nil) end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
144 145 146 |
# File 'lib/rbs/types.rb', line 144 def ==(other) other.is_a?(Variable) && other.name == name end |
#free_variables(set = Set.new) ⇒ Object
154 155 156 157 158 |
# File 'lib/rbs/types.rb', line 154 def free_variables(set = Set.new) set.tap do set << name end end |
#has_classish_type? ⇒ Boolean
193 194 195 |
# File 'lib/rbs/types.rb', line 193 def has_classish_type? false end |
#has_self_type? ⇒ Boolean
189 190 191 |
# File 'lib/rbs/types.rb', line 189 def has_self_type? false end |
#hash ⇒ Object
150 151 152 |
# File 'lib/rbs/types.rb', line 150 def hash self.class.hash ^ name.hash end |
#sub(s) ⇒ Object
164 165 166 |
# File 'lib/rbs/types.rb', line 164 def sub(s) s.apply(self) end |
#to_json(state = _ = nil) ⇒ Object
160 161 162 |
# File 'lib/rbs/types.rb', line 160 def to_json(state = _ = nil) { class: :variable, name: name, location: location }.to_json(state) end |
#to_s(level = 0) ⇒ Object
183 184 185 |
# File 'lib/rbs/types.rb', line 183 def to_s(level = 0) name.to_s end |
#with_nonreturn_void? ⇒ Boolean
197 198 199 |
# File 'lib/rbs/types.rb', line 197 def with_nonreturn_void? false end |