Class: RBS::Types::ClassSingleton

Inherits:
Object
  • Object
show all
Includes:
Application
Defined in:
lib/rbs/types.rb

Instance Attribute Summary collapse

Attributes included from Application

#args, #name

Instance Method Summary collapse

Methods included from Application

#each_type, #free_variables, #has_classish_type?, #has_self_type?, #with_nonreturn_void?

Constructor Details

#initialize(name:, location:, args: []) ⇒ ClassSingleton

Returns a new instance of ClassSingleton.



265
266
267
268
269
# File 'lib/rbs/types.rb', line 265

def initialize(name:, location:, args: [])
  @name = name
  @location = location
  @args = args
end

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



261
262
263
# File 'lib/rbs/types.rb', line 261

def location
  @location
end

Instance Method Details

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



271
272
273
# File 'lib/rbs/types.rb', line 271

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

#hashObject



277
278
279
# File 'lib/rbs/types.rb', line 277

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

#map_type(&block) ⇒ Object



309
310
311
312
313
314
315
316
317
318
319
# File 'lib/rbs/types.rb', line 309

def map_type(&block)
  if block
    ClassSingleton.new(
      name: name,
      args: args.map {|type| yield type },
      location: location
    )
  else
    enum_for :map_type
  end
end

#map_type_name(&block) ⇒ Object



301
302
303
304
305
306
307
# File 'lib/rbs/types.rb', line 301

def map_type_name(&block)
  ClassSingleton.new(
    name: yield(name, location, self),
    args: args.map {|type| type.map_type_name(&block) },
    location: location
  )
end

#sub(s) ⇒ Object



281
282
283
284
285
286
287
# File 'lib/rbs/types.rb', line 281

def sub(s)
  return self if s.empty?

  self.class.new(name: name,
                 args: args.map {|ty| ty.sub(s) },
                 location: location)
end

#to_json(state = _ = nil) ⇒ Object



289
290
291
# File 'lib/rbs/types.rb', line 289

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

#to_s(level = 0) ⇒ Object



293
294
295
296
297
298
299
# File 'lib/rbs/types.rb', line 293

def to_s(level = 0)
  if args.empty?
    "singleton(#{name})"
  else
    "singleton(#{name})[#{args.join(", ")}]"
  end
end