Class: SyntaxTree::Const
- Inherits:
-
Object
- Object
- SyntaxTree::Const
- Defined in:
- lib/syntax_tree.rb
Overview
Const represents a literal value that looks like a constant. This could actually be a reference to a constant:
Constant
It could also be something that looks like a constant in another context, as in a method call to a capitalized method:
object.Constant
or a symbol that starts with a capital letter:
:Constant
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 name of the constant.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, location:, comments: []) ⇒ Const
constructor
A new instance of Const.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(value:, location:, comments: []) ⇒ Const
3997 3998 3999 4000 4001 |
# File 'lib/syntax_tree.rb', line 3997 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
3995 3996 3997 |
# File 'lib/syntax_tree.rb', line 3995 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
3992 3993 3994 |
# File 'lib/syntax_tree.rb', line 3992 def location @location end |
#value ⇒ Object (readonly)
- String
-
the name of the constant
3989 3990 3991 |
# File 'lib/syntax_tree.rb', line 3989 def value @value end |
Instance Method Details
#child_nodes ⇒ Object
4003 4004 4005 |
# File 'lib/syntax_tree.rb', line 4003 def child_nodes [] end |
#format(q) ⇒ Object
4007 4008 4009 |
# File 'lib/syntax_tree.rb', line 4007 def format(q) q.text(value) end |
#pretty_print(q) ⇒ Object
4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 |
# File 'lib/syntax_tree.rb', line 4011 def pretty_print(q) q.group(2, "(", ")") do q.text("const") q.breakable q.pp(value) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
4022 4023 4024 4025 4026 |
# File 'lib/syntax_tree.rb', line 4022 def to_json(*opts) { type: :const, value: value, loc: location, cmts: comments }.to_json( *opts ) end |