Class: SyntaxTree::EndContent

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.rb

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

Attributes inherited from Node

#location

Instance Method Summary collapse

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

#commentsObject (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

#valueObject (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_nodesObject 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
# File 'lib/syntax_tree/node.rb', line 328

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