Class: SyntaxTree::IVar
- Inherits:
-
Object
- Object
- SyntaxTree::IVar
- Defined in:
- lib/syntax_tree.rb
Overview
IVar represents an instance variable literal.
@variable
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 instance variable.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, location:, comments: []) ⇒ IVar
constructor
A new instance of IVar.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(value:, location:, comments: []) ⇒ IVar
Returns a new instance of IVar.
7406 7407 7408 7409 7410 |
# File 'lib/syntax_tree.rb', line 7406 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
7404 7405 7406 |
# File 'lib/syntax_tree.rb', line 7404 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
7401 7402 7403 |
# File 'lib/syntax_tree.rb', line 7401 def location @location end |
#value ⇒ Object (readonly)
- String
-
the name of the instance variable
7398 7399 7400 |
# File 'lib/syntax_tree.rb', line 7398 def value @value end |
Instance Method Details
#child_nodes ⇒ Object
7412 7413 7414 |
# File 'lib/syntax_tree.rb', line 7412 def child_nodes [] end |
#format(q) ⇒ Object
7416 7417 7418 |
# File 'lib/syntax_tree.rb', line 7416 def format(q) q.text(value) end |
#pretty_print(q) ⇒ Object
7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 |
# File 'lib/syntax_tree.rb', line 7420 def pretty_print(q) q.group(2, "(", ")") do q.text("ivar") q.breakable q.pp(value) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
7431 7432 7433 7434 7435 |
# File 'lib/syntax_tree.rb', line 7431 def to_json(*opts) { type: :ivar, value: value, loc: location, cmts: comments }.to_json( *opts ) end |