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.



315
316
317
318
319
320
# File 'lib/rbs/ast/declarations.rb', line 315

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.



313
314
315
# File 'lib/rbs/ast/declarations.rb', line 313

def comment
  @comment
end

#locationObject (readonly)

Returns the value of attribute location.



312
313
314
# File 'lib/rbs/ast/declarations.rb', line 312

def location
  @location
end

#nameObject (readonly)

Returns the value of attribute name.



310
311
312
# File 'lib/rbs/ast/declarations.rb', line 310

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



311
312
313
# File 'lib/rbs/ast/declarations.rb', line 311

def type
  @type
end

Instance Method Details

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



322
323
324
325
326
# File 'lib/rbs/ast/declarations.rb', line 322

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

#hashObject



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

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

#to_json(state = _ = nil) ⇒ Object



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

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