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
Returns a new instance of Const.
4159 4160 4161 4162 4163 |
# File 'lib/syntax_tree.rb', line 4159 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
4157 4158 4159 |
# File 'lib/syntax_tree.rb', line 4157 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
4154 4155 4156 |
# File 'lib/syntax_tree.rb', line 4154 def location @location end |
#value ⇒ Object (readonly)
- String
-
the name of the constant
4151 4152 4153 |
# File 'lib/syntax_tree.rb', line 4151 def value @value end |
Instance Method Details
#child_nodes ⇒ Object
4165 4166 4167 |
# File 'lib/syntax_tree.rb', line 4165 def child_nodes [] end |
#format(q) ⇒ Object
4169 4170 4171 |
# File 'lib/syntax_tree.rb', line 4169 def format(q) q.text(value) end |
#pretty_print(q) ⇒ Object
4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 |
# File 'lib/syntax_tree.rb', line 4173 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
4184 4185 4186 4187 4188 |
# File 'lib/syntax_tree.rb', line 4184 def to_json(*opts) { type: :const, value: value, loc: location, cmts: comments }.to_json( *opts ) end |