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

Inherits:
Base
  • Object
show all
Defined in:
lib/rbs/ast/declarations.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, type:, location:, comment:) ⇒ Constant

Returns a new instance of Constant.



435
436
437
438
439
440
# File 'lib/rbs/ast/declarations.rb', line 435

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

Instance Attribute Details

#commentObject (readonly)

Returns the value of attribute comment.



433
434
435
# File 'lib/rbs/ast/declarations.rb', line 433

def comment
  @comment
end

#locationObject (readonly)

Returns the value of attribute location.



432
433
434
# File 'lib/rbs/ast/declarations.rb', line 432

def location
  @location
end

#nameObject (readonly)

Returns the value of attribute name.



430
431
432
# File 'lib/rbs/ast/declarations.rb', line 430

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



431
432
433
# File 'lib/rbs/ast/declarations.rb', line 431

def type
  @type
end

Instance Method Details

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



442
443
444
445
446
# File 'lib/rbs/ast/declarations.rb', line 442

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

#hashObject



450
451
452
# File 'lib/rbs/ast/declarations.rb', line 450

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

#to_json(*a) ⇒ Object



454
455
456
457
458
459
460
461
462
# File 'lib/rbs/ast/declarations.rb', line 454

def to_json(*a)
  {
    declaration: :constant,
    name: name,
    type: type,
    location: location,
    comment: comment
  }.to_json(*a)
end