Class: SyntaxTree::RationalLiteral

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.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.



8439
8440
8441
8442
8443
# File 'lib/syntax_tree/node.rb', line 8439

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



8437
8438
8439
# File 'lib/syntax_tree/node.rb', line 8437

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



8434
8435
8436
# File 'lib/syntax_tree/node.rb', line 8434

def location
  @location
end

#valueObject (readonly)

String

the rational number literal



8431
8432
8433
# File 'lib/syntax_tree/node.rb', line 8431

def value
  @value
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



8445
8446
8447
# File 'lib/syntax_tree/node.rb', line 8445

def child_nodes
  []
end

#deconstruct_keys(keys) ⇒ Object



8451
8452
8453
# File 'lib/syntax_tree/node.rb', line 8451

def deconstruct_keys(keys)
  { value: value, location: location, comments: comments }
end

#format(q) ⇒ Object



8455
8456
8457
# File 'lib/syntax_tree/node.rb', line 8455

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

#pretty_print(q) ⇒ Object



8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
# File 'lib/syntax_tree/node.rb', line 8459

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



8470
8471
8472
8473
8474
# File 'lib/syntax_tree/node.rb', line 8470

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