Class: RBS::AST::Declarations::Global

Inherits:
Base
  • Object
show all
Includes:
_ToJson, _HashEqual
Defined in:
lib/rbs/ast/declarations.rb,
sig/declarations.rbs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, type:, location:, comment:, annotations:) ⇒ void #initializevoid

Returns a new instance of Global.

Overloads:

  • #initialize(name:, type:, location:, comment:, annotations:) ⇒ void

    Parameters:

    • name: (Symbol)
    • type: (Types::t)
    • location: (loc, nil)
    • comment: (Comment, nil)
    • annotations: (Array[Annotation])
  • #initializevoid


392
393
394
395
396
397
398
# File 'lib/rbs/ast/declarations.rb', line 392

def initialize(name:, type:, location:, comment:, annotations: [])
  @name = name
  @type = type
  @location = location
  @comment = comment
  @annotations = annotations
end

Instance Attribute Details

#annotationsArray[Annotation] (readonly)

Returns the value of attribute annotations.

Returns:



390
391
392
# File 'lib/rbs/ast/declarations.rb', line 390

def annotations
  @annotations
end

#commentComment? (readonly)

Returns the value of attribute comment.

Returns:



389
390
391
# File 'lib/rbs/ast/declarations.rb', line 389

def comment
  @comment
end

#locationloc? (readonly)

Returns the value of attribute location.

Returns:

  • (loc, nil)


388
389
390
# File 'lib/rbs/ast/declarations.rb', line 388

def location
  @location
end

#nameSymbol (readonly)

Returns the value of attribute name.

Returns:

  • (Symbol)


386
387
388
# File 'lib/rbs/ast/declarations.rb', line 386

def name
  @name
end

#typeTypes::t (readonly)

Returns the value of attribute type.

Returns:

  • (Types::t)


387
388
389
# File 'lib/rbs/ast/declarations.rb', line 387

def type
  @type
end

Instance Method Details

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



400
401
402
403
404
# File 'lib/rbs/ast/declarations.rb', line 400

def ==(other)
  other.is_a?(Global) &&
    other.name == name &&
    other.type == type
end

#hashObject



408
409
410
# File 'lib/rbs/ast/declarations.rb', line 408

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

#to_json(state = nil) ⇒ Object



412
413
414
415
416
417
418
419
420
# File 'lib/rbs/ast/declarations.rb', line 412

def to_json(state = nil)
  {
    declaration: :global,
    name: name,
    type: type,
    location: location,
    comment: comment
  }.to_json(state)
end