Class: RBS::AST::Declarations::Constant

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 Constant.

Overloads:

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

    Parameters:

  • #initializevoid


354
355
356
357
358
359
360
# File 'lib/rbs/ast/declarations.rb', line 354

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:



352
353
354
# File 'lib/rbs/ast/declarations.rb', line 352

def annotations
  @annotations
end

#commentComment? (readonly)

Returns the value of attribute comment.

Returns:



351
352
353
# File 'lib/rbs/ast/declarations.rb', line 351

def comment
  @comment
end

#locationloc? (readonly)

Returns the value of attribute location.

Returns:

  • (loc, nil)


350
351
352
# File 'lib/rbs/ast/declarations.rb', line 350

def location
  @location
end

#nameTypeName (readonly)

Returns the value of attribute name.

Returns:



348
349
350
# File 'lib/rbs/ast/declarations.rb', line 348

def name
  @name
end

#typeTypes::t (readonly)

Returns the value of attribute type.

Returns:

  • (Types::t)


349
350
351
# File 'lib/rbs/ast/declarations.rb', line 349

def type
  @type
end

Instance Method Details

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



362
363
364
365
366
# File 'lib/rbs/ast/declarations.rb', line 362

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

#hashObject



370
371
372
# File 'lib/rbs/ast/declarations.rb', line 370

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

#to_json(state = nil) ⇒ Object



374
375
376
377
378
379
380
381
382
# File 'lib/rbs/ast/declarations.rb', line 374

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