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.



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

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.



410
411
412
# File 'lib/rbs/ast/declarations.rb', line 410

def comment
  @comment
end

#locationObject (readonly)

Returns the value of attribute location.



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

def location
  @location
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

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



419
420
421
422
423
# File 'lib/rbs/ast/declarations.rb', line 419

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

#hashObject



427
428
429
# File 'lib/rbs/ast/declarations.rb', line 427

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

#to_json(state = _ = nil) ⇒ Object



431
432
433
434
435
436
437
438
439
# File 'lib/rbs/ast/declarations.rb', line 431

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