Class: SyntaxTree::RationalLiteral
Overview
RationalLiteral represents the use of a rational number literal.
1r
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#value ⇒ Object
readonly
- String
-
the rational number literal.
Instance Method Summary collapse
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, location:, comments: []) ⇒ RationalLiteral
constructor
A new instance of RationalLiteral.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
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
#comments ⇒ Object (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 |
#location ⇒ Object (readonly)
- Location
-
the location of this node
8434 8435 8436 |
# File 'lib/syntax_tree/node.rb', line 8434 def location @location end |
#value ⇒ Object (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_nodes ⇒ Object 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 |