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.



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

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.



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

def comment
  @comment
end

#locationObject (readonly)

Returns the value of attribute location.



405
406
407
# File 'lib/rbs/ast/declarations.rb', line 405

def location
  @location
end

#nameObject (readonly)

Returns the value of attribute name.



403
404
405
# File 'lib/rbs/ast/declarations.rb', line 403

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



404
405
406
# File 'lib/rbs/ast/declarations.rb', line 404

def type
  @type
end

Instance Method Details

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



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

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

#hashObject



423
424
425
# File 'lib/rbs/ast/declarations.rb', line 423

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

#to_json(state = _ = nil) ⇒ Object



427
428
429
430
431
432
433
434
435
# File 'lib/rbs/ast/declarations.rb', line 427

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