Class: SyntaxTree::RationalLiteral

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree.rb

Overview

RationalLiteral represents the use of a rational number literal.

1r

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value:, location:, comments: []) ⇒ RationalLiteral

Returns a new instance of RationalLiteral.



9258
9259
9260
9261
9262
# File 'lib/syntax_tree.rb', line 9258

def initialize(value:, location:, comments: [])
  @value = value
  @location = location
  @comments = comments
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



9256
9257
9258
# File 'lib/syntax_tree.rb', line 9256

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



9253
9254
9255
# File 'lib/syntax_tree.rb', line 9253

def location
  @location
end

#valueObject (readonly)

String

the rational number literal



9250
9251
9252
# File 'lib/syntax_tree.rb', line 9250

def value
  @value
end

Instance Method Details

#child_nodesObject



9264
9265
9266
# File 'lib/syntax_tree.rb', line 9264

def child_nodes
  []
end

#format(q) ⇒ Object



9268
9269
9270
# File 'lib/syntax_tree.rb', line 9268

def format(q)
  q.text(value)
end

#pretty_print(q) ⇒ Object



9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
# File 'lib/syntax_tree.rb', line 9272

def pretty_print(q)
  q.group(2, "(", ")") do
    q.text("rational")

    q.breakable
    q.pp(value)

    q.pp(Comment::List.new(comments))
  end
end

#to_json(*opts) ⇒ Object



9283
9284
9285
9286
9287
# File 'lib/syntax_tree.rb', line 9283

def to_json(*opts)
  { type: :rational, value: value, loc: location, cmts: comments }.to_json(
    *opts
  )
end