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
Returns a new instance of Variable.
137 138 139 140 |
# File 'lib/rbs/types.rb', line 137 def initialize(name:, location:) @name = name @location = location end |
Instance Attribute Details
#location ⇒ Object (readonly)
Returns the value of attribute location.
133 134 135 |
# File 'lib/rbs/types.rb', line 133 def location @location end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
132 133 134 |
# File 'lib/rbs/types.rb', line 132 def name @name end |
Class Method Details
.build(v) ⇒ Object
166 167 168 169 170 171 172 173 |
# File 'lib/rbs/types.rb', line 166 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
176 177 178 179 |
# File 'lib/rbs/types.rb', line 176 def self.fresh(v = :T) @@count = @@count + 1 new(name: :"#{v}@#{@@count}", location: nil) end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
142 143 144 |
# File 'lib/rbs/types.rb', line 142 def ==(other) other.is_a?(Variable) && other.name == name end |
#free_variables(set = Set.new) ⇒ Object
152 153 154 155 156 |
# File 'lib/rbs/types.rb', line 152 def free_variables(set = Set.new) set.tap do set << name end end |
#has_classish_type? ⇒ Boolean
191 192 193 |
# File 'lib/rbs/types.rb', line 191 def has_classish_type? false end |
#has_self_type? ⇒ Boolean
187 188 189 |
# File 'lib/rbs/types.rb', line 187 def has_self_type? false end |
#hash ⇒ Object
148 149 150 |
# File 'lib/rbs/types.rb', line 148 def hash self.class.hash ^ name.hash end |
#sub(s) ⇒ Object
162 163 164 |
# File 'lib/rbs/types.rb', line 162 def sub(s) s.apply(self) end |
#to_json(state = _ = nil) ⇒ Object
158 159 160 |
# File 'lib/rbs/types.rb', line 158 def to_json(state = _ = nil) { class: :variable, name: name, location: location }.to_json(state) end |
#to_s(level = 0) ⇒ Object
181 182 183 |
# File 'lib/rbs/types.rb', line 181 def to_s(level = 0) name.to_s end |
#with_nonreturn_void? ⇒ Boolean
195 196 197 |
# File 'lib/rbs/types.rb', line 195 def with_nonreturn_void? false end |