Class: RBS::Types::Variable

Inherits:
Object
  • Object
show all
Includes:
EmptyEachType, NoTypeName
Defined in:
lib/rbs/types.rb

Constant Summary collapse

@@count =
0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from EmptyEachType

#each_type, #map_type

Methods included from NoTypeName

#map_type_name

Constructor Details

#initialize(name:, location:) ⇒ Variable

Returns a new instance of Variable.



116
117
118
119
# File 'lib/rbs/types.rb', line 116

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

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



112
113
114
# File 'lib/rbs/types.rb', line 112

def location
  @location
end

#nameObject (readonly)

Returns the value of attribute name.



111
112
113
# File 'lib/rbs/types.rb', line 111

def name
  @name
end

Class Method Details

.build(v) ⇒ Object



145
146
147
148
149
150
151
152
# File 'lib/rbs/types.rb', line 145

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



155
156
157
158
# File 'lib/rbs/types.rb', line 155

def self.fresh(v = :T)
  @@count = @@count + 1
  new(name: :"#{v}@#{@@count}", location: nil)
end

Instance Method Details

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



121
122
123
# File 'lib/rbs/types.rb', line 121

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

#free_variables(set = Set.new) ⇒ Object



131
132
133
134
135
# File 'lib/rbs/types.rb', line 131

def free_variables(set = Set.new)
  set.tap do
    set << name
  end
end

#hashObject



127
128
129
# File 'lib/rbs/types.rb', line 127

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

#sub(s) ⇒ Object



141
142
143
# File 'lib/rbs/types.rb', line 141

def sub(s)
  s.apply(self)
end

#to_json(state = _ = nil) ⇒ Object



137
138
139
# File 'lib/rbs/types.rb', line 137

def to_json(state = _ = nil)
  { class: :variable, name: name, location: location }.to_json(state)
end

#to_s(level = 0) ⇒ Object



160
161
162
# File 'lib/rbs/types.rb', line 160

def to_s(level = 0)
  name.to_s
end