Class: RBS::Types::ClassSingleton

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from EmptyEachType

#each_type, #map_type

Methods included from NoSubst

#sub

Methods included from NoFreeVariables

#free_variables

Constructor Details

#initialize(name:, location:) ⇒ ClassSingleton

Returns a new instance of ClassSingleton.



171
172
173
174
# File 'lib/rbs/types.rb', line 171

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

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



169
170
171
# File 'lib/rbs/types.rb', line 169

def location
  @location
end

#nameObject (readonly)

Returns the value of attribute name.



168
169
170
# File 'lib/rbs/types.rb', line 168

def name
  @name
end

Instance Method Details

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



176
177
178
# File 'lib/rbs/types.rb', line 176

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

#hashObject



182
183
184
# File 'lib/rbs/types.rb', line 182

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

#map_type_nameObject



199
200
201
202
203
204
# File 'lib/rbs/types.rb', line 199

def map_type_name
  ClassSingleton.new(
    name: yield(name, location, self),
    location: location
  )
end

#to_json(state = _ = nil) ⇒ Object



189
190
191
# File 'lib/rbs/types.rb', line 189

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

#to_s(level = 0) ⇒ Object



193
194
195
# File 'lib/rbs/types.rb', line 193

def to_s(level = 0)
  "singleton(#{name})"
end