Class: RBS::AST::Comment

Inherits:
Object
  • Object
show all
Defined in:
lib/rbs/ast/comment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string:, location:) ⇒ Comment

Returns a new instance of Comment.



7
8
9
10
# File 'lib/rbs/ast/comment.rb', line 7

def initialize(string:, location:)
  @string = string
  @location = location
end

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



5
6
7
# File 'lib/rbs/ast/comment.rb', line 5

def location
  @location
end

#stringObject (readonly)

Returns the value of attribute string.



4
5
6
# File 'lib/rbs/ast/comment.rb', line 4

def string
  @string
end

Instance Method Details

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



12
13
14
# File 'lib/rbs/ast/comment.rb', line 12

def ==(other)
  other.is_a?(Comment) && other.string == string
end

#concat(string:, location:) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rbs/ast/comment.rb', line 26

def concat(string:, location:)
  @string.concat string

  if loc = @location
    loc.concat location
  else
    @location = location
  end

  self
end

#hashObject



18
19
20
# File 'lib/rbs/ast/comment.rb', line 18

def hash
  self.class.hash ^ string.hash
end

#to_json(state = _ = nil) ⇒ Object



22
23
24
# File 'lib/rbs/ast/comment.rb', line 22

def to_json(state = _ = nil)
  { string: string, location: location }.to_json(state)
end