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.



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

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.



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

def comment
  @comment
end

#locationObject (readonly)

Returns the value of attribute location.



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

def location
  @location
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

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



324
325
326
327
328
# File 'lib/rbs/ast/declarations.rb', line 324

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

#hashObject



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

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

#to_json(state = _ = nil) ⇒ Object



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

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