Class: SyntaxTree::StringEmbExpr
Overview
StringEmbExpr represents interpolated content. It can be contained within a couple of different parent nodes, including regular expressions, strings, and dynamic symbols.
"string #{expression}"
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.
-
#statements ⇒ Object
readonly
- Statements
-
the expressions to be interpolated.
Instance Method Summary collapse
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(statements:, location:, comments: []) ⇒ StringEmbExpr
constructor
A new instance of StringEmbExpr.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(statements:, location:, comments: []) ⇒ StringEmbExpr
Returns a new instance of StringEmbExpr.
9689 9690 9691 9692 9693 |
# File 'lib/syntax_tree/node.rb', line 9689 def initialize(statements:, location:, comments: []) @statements = statements @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
9687 9688 9689 |
# File 'lib/syntax_tree/node.rb', line 9687 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
9684 9685 9686 |
# File 'lib/syntax_tree/node.rb', line 9684 def location @location end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be interpolated
9681 9682 9683 |
# File 'lib/syntax_tree/node.rb', line 9681 def statements @statements end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
9695 9696 9697 |
# File 'lib/syntax_tree/node.rb', line 9695 def child_nodes [statements] end |
#deconstruct_keys(keys) ⇒ Object
9701 9702 9703 |
# File 'lib/syntax_tree/node.rb', line 9701 def deconstruct_keys(keys) { statements: statements, location: location, comments: comments } end |
#format(q) ⇒ Object
9705 9706 9707 9708 9709 9710 9711 9712 9713 9714 9715 9716 9717 9718 9719 9720 9721 9722 9723 9724 |
# File 'lib/syntax_tree/node.rb', line 9705 def format(q) if location.start_line == location.end_line # If the contents of this embedded expression were originally on the # same line in the source, then we're going to leave them in place and # assume that's the way the developer wanted this expression # represented. doc = q.group(0, '#{', "}") { q.format(statements) } RemoveBreaks.call(doc) else q.group do q.text('#{') q.indent do q.breakable("") q.format(statements) end q.breakable("") q.text("}") end end end |
#pretty_print(q) ⇒ Object
9726 9727 9728 9729 9730 9731 9732 9733 9734 9735 |
# File 'lib/syntax_tree/node.rb', line 9726 def pretty_print(q) q.group(2, "(", ")") do q.text("string_embexpr") q.breakable q.pp(statements) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
9737 9738 9739 9740 9741 9742 9743 9744 |
# File 'lib/syntax_tree/node.rb', line 9737 def to_json(*opts) { type: :string_embexpr, stmts: statements, loc: location, cmts: comments }.to_json(*opts) end |