Class: RBS::AST::Annotation

Inherits:
Object
  • Object
show all
Includes:
_ToJson
Defined in:
sig/annotation.rbs,
lib/rbs/ast/annotation.rb

Overview

RBS allows writing annotations of declarations and members.

%a{annotation_here}
class Hello
  %a{rbs:test:skip}
  def foo: () -> void
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string:, location:) ⇒ Annotation

Returns a new instance of Annotation.

Parameters:

  • string: (String)
  • location: (Location[untyped, untyped], nil)


9
10
11
12
# File 'lib/rbs/ast/annotation.rb', line 9

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

Instance Attribute Details

#locationLocation[untyped, untyped]? (readonly)

Returns the value of attribute location.

Returns:



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

def location
  @location
end

#stringString (readonly)

Returns the value of attribute string.

Returns:

  • (String)


6
7
8
# File 'lib/rbs/ast/annotation.rb', line 6

def string
  @string
end

Instance Method Details

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

Parameters:

  • other (Object)

Returns:

  • (Boolean)


14
15
16
# File 'lib/rbs/ast/annotation.rb', line 14

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

#hashInteger

Returns:

  • (Integer)


20
21
22
# File 'lib/rbs/ast/annotation.rb', line 20

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

#to_json(state = nil) ⇒ Object



24
25
26
# File 'lib/rbs/ast/annotation.rb', line 24

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