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
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, location:, comments: []) ⇒ EndContent
constructor
A new instance of EndContent.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(value:, location:, comments: []) ⇒ EndContent
Returns a new instance of EndContent.
309 310 311 312 313 |
# File 'lib/syntax_tree/node.rb', line 309 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
307 308 309 |
# File 'lib/syntax_tree/node.rb', line 307 def comments @comments end |
#value ⇒ Object (readonly)
- String
-
the content after the script
304 305 306 |
# File 'lib/syntax_tree/node.rb', line 304 def value @value end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
315 316 317 |
# File 'lib/syntax_tree/node.rb', line 315 def child_nodes [] end |
#deconstruct_keys(keys) ⇒ Object
321 322 323 |
# File 'lib/syntax_tree/node.rb', line 321 def deconstruct_keys(keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
325 326 327 328 329 330 331 |
# File 'lib/syntax_tree/node.rb', line 325 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 |
#pretty_print(q) ⇒ Object
333 334 335 336 337 338 339 340 341 342 |
# File 'lib/syntax_tree/node.rb', line 333 def pretty_print(q) q.group(2, "(", ")") do q.text("__end__") q.breakable q.pp(value) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
344 345 346 347 348 |
# File 'lib/syntax_tree/node.rb', line 344 def to_json(*opts) { type: :__end__, value: value, loc: location, cmts: comments }.to_json( *opts ) end |