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

#pretty_print, #to_json

Constructor Details

#initialize(value:, location:, comments: []) ⇒ EndContent

Returns a new instance of EndContent.



285
286
287
288
289
# File 'lib/syntax_tree/node.rb', line 285

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



283
284
285
# File 'lib/syntax_tree/node.rb', line 283

def comments
  @comments
end

#valueObject (readonly)

String

the content after the script



280
281
282
# File 'lib/syntax_tree/node.rb', line 280

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



291
292
293
# File 'lib/syntax_tree/node.rb', line 291

def accept(visitor)
  visitor.visit___end__(self)
end

#child_nodesObject Also known as: deconstruct



295
296
297
# File 'lib/syntax_tree/node.rb', line 295

def child_nodes
  []
end

#deconstruct_keys(keys) ⇒ Object



301
302
303
# File 'lib/syntax_tree/node.rb', line 301

def deconstruct_keys(keys)
  { value: value, location: location, comments: comments }
end

#format(q) ⇒ Object



305
306
307
308
309
310
311
# File 'lib/syntax_tree/node.rb', line 305

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