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
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
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(value:, location:, comments: []) ⇒ EndContent
Returns a new instance of EndContent.
308 309 310 311 312 |
# File 'lib/syntax_tree/node.rb', line 308 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
306 307 308 |
# File 'lib/syntax_tree/node.rb', line 306 def comments @comments end |
#value ⇒ Object (readonly)
- String
-
the content after the script
303 304 305 |
# File 'lib/syntax_tree/node.rb', line 303 def value @value end |
Instance Method Details
#accept(visitor) ⇒ Object
314 315 316 |
# File 'lib/syntax_tree/node.rb', line 314 def accept(visitor) visitor.visit___end__(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
318 319 320 |
# File 'lib/syntax_tree/node.rb', line 318 def child_nodes [] end |
#deconstruct_keys(_keys) ⇒ Object
324 325 326 |
# File 'lib/syntax_tree/node.rb', line 324 def deconstruct_keys(_keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 |
# File 'lib/syntax_tree/node.rb', line 328 def format(q) q.text("__END__") q.breakable_force first = true value.each_line(chomp: true) do |line| if first first = false else q.breakable_return end q.text(line) end q.breakable_return if value.end_with?("\n") end |