Class: SyntaxTree::EndContent
Overview
EndContent represents the use of END syntax, which allows individual scripts to keep content after the main ruby code that can be read through the DATA constant.
puts DATA.read
__END__
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
[Array[ Comment | EmbDoc ]] the comments attached to this node.
-
#value ⇒ Object
readonly
[String] the content after the script.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, location:, comments: []) ⇒ EndContent
constructor
A new instance of EndContent.
Methods inherited from Node
Constructor Details
#initialize(value:, location:, comments: []) ⇒ EndContent
Returns a new instance of EndContent.
285 286 287 288 289 |
# File 'lib/syntax_tree/node.rb', line 285 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
283 284 285 |
# File 'lib/syntax_tree/node.rb', line 283 def comments @comments end |
#value ⇒ Object (readonly)
[String] the content after the script
280 281 282 |
# File 'lib/syntax_tree/node.rb', line 280 def value @value end |
Instance Method Details
#accept(visitor) ⇒ Object
291 292 293 |
# File 'lib/syntax_tree/node.rb', line 291 def accept(visitor) visitor.visit___end__(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
295 296 297 |
# File 'lib/syntax_tree/node.rb', line 295 def child_nodes [] end |
#deconstruct_keys(keys) ⇒ Object
301 302 303 |
# File 'lib/syntax_tree/node.rb', line 301 def deconstruct_keys(keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
305 306 307 308 309 310 311 |
# File 'lib/syntax_tree/node.rb', line 305 def format(q) q.text("__END__") q.breakable(force: true) separator = -> { q.breakable(indent: false, force: true) } q.seplist(value.split(/\r?\n/, -1), separator) { |line| q.text(line) } end |