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

Inherits:
Object
  • 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.



336
337
338
339
340
341
# File 'lib/rbs/ast/declarations.rb', line 336

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.



334
335
336
# File 'lib/rbs/ast/declarations.rb', line 334

def comment
  @comment
end

#locationObject (readonly)

Returns the value of attribute location.



333
334
335
# File 'lib/rbs/ast/declarations.rb', line 333

def location
  @location
end

#nameObject (readonly)

Returns the value of attribute name.



331
332
333
# File 'lib/rbs/ast/declarations.rb', line 331

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



332
333
334
# File 'lib/rbs/ast/declarations.rb', line 332

def type
  @type
end

Instance Method Details

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



343
344
345
346
347
# File 'lib/rbs/ast/declarations.rb', line 343

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

#hashObject



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

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

#to_json(*a) ⇒ Object



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

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