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.
7479 7480 7481 7482 7483 |
# File 'lib/syntax_tree.rb', line 7479 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
7477 7478 7479 |
# File 'lib/syntax_tree.rb', line 7477 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
7474 7475 7476 |
# File 'lib/syntax_tree.rb', line 7474 def location @location end |
#value ⇒ Object (readonly)
- String
-
the name of the instance variable
7471 7472 7473 |
# File 'lib/syntax_tree.rb', line 7471 def value @value end |
Instance Method Details
#child_nodes ⇒ Object
7485 7486 7487 |
# File 'lib/syntax_tree.rb', line 7485 def child_nodes [] end |
#format(q) ⇒ Object
7489 7490 7491 |
# File 'lib/syntax_tree.rb', line 7489 def format(q) q.text(value) end |
#pretty_print(q) ⇒ Object
7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 |
# File 'lib/syntax_tree.rb', line 7493 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
7504 7505 7506 7507 7508 |
# File 'lib/syntax_tree.rb', line 7504 def to_json(*opts) { type: :ivar, value: value, loc: location, cmts: comments }.to_json( *opts ) end |