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

__END__

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#pretty_print, #to_json

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

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

#valueObject (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_nodesObject 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