Class: SyntaxTree::RationalLiteral
- Inherits:
-
Object
- Object
- SyntaxTree::RationalLiteral
- Defined in:
- lib/syntax_tree.rb
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
- #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.
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
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
9256 9257 9258 |
# File 'lib/syntax_tree.rb', line 9256 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
9253 9254 9255 |
# File 'lib/syntax_tree.rb', line 9253 def location @location end |
#value ⇒ Object (readonly)
- String
-
the rational number literal
9250 9251 9252 |
# File 'lib/syntax_tree.rb', line 9250 def value @value end |
Instance Method Details
#child_nodes ⇒ Object
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 |