Class: SyntaxTree::EndContent

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree.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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of EndContent.



618
619
620
621
622
# File 'lib/syntax_tree.rb', line 618

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



616
617
618
# File 'lib/syntax_tree.rb', line 616

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



613
614
615
# File 'lib/syntax_tree.rb', line 613

def location
  @location
end

#valueObject (readonly)

String

the content after the script



610
611
612
# File 'lib/syntax_tree.rb', line 610

def value
  @value
end

Instance Method Details

#child_nodesObject



624
625
626
# File 'lib/syntax_tree.rb', line 624

def child_nodes
  []
end

#format(q) ⇒ Object



628
629
630
631
632
# File 'lib/syntax_tree.rb', line 628

def format(q)
  q.text("__END__")
  q.breakable(force: true)
  q.text(value)
end

#pretty_print(q) ⇒ Object



634
635
636
637
638
639
640
641
642
643
# File 'lib/syntax_tree.rb', line 634

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



645
646
647
648
649
# File 'lib/syntax_tree.rb', line 645

def to_json(*opts)
  { type: :__end__, value: value, loc: location, cmts: comments }.to_json(
    *opts
  )
end