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.
270 271 272 273 274 |
# File 'lib/syntax_tree/node.rb', line 270 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
268 269 270 |
# File 'lib/syntax_tree/node.rb', line 268 def comments @comments end |
#value ⇒ Object (readonly)
- String
-
the content after the script
265 266 267 |
# File 'lib/syntax_tree/node.rb', line 265 def value @value end |
Instance Method Details
#accept(visitor) ⇒ Object
276 277 278 |
# File 'lib/syntax_tree/node.rb', line 276 def accept(visitor) visitor.visit___end__(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
280 281 282 |
# File 'lib/syntax_tree/node.rb', line 280 def child_nodes [] end |
#deconstruct_keys(keys) ⇒ Object
286 287 288 |
# File 'lib/syntax_tree/node.rb', line 286 def deconstruct_keys(keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
290 291 292 293 294 295 296 |
# File 'lib/syntax_tree/node.rb', line 290 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 |