Class: SyntaxTree::EndContent
- Inherits:
-
Object
- Object
- SyntaxTree::EndContent
- 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
__END__
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#value ⇒ Object
readonly
- String
-
the content after the script.
Instance Method Summary collapse
- #child_nodes ⇒ 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.
667 668 669 670 671 |
# File 'lib/syntax_tree.rb', line 667 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
665 666 667 |
# File 'lib/syntax_tree.rb', line 665 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
662 663 664 |
# File 'lib/syntax_tree.rb', line 662 def location @location end |
#value ⇒ Object (readonly)
- String
-
the content after the script
659 660 661 |
# File 'lib/syntax_tree.rb', line 659 def value @value end |
Instance Method Details
#child_nodes ⇒ Object
673 674 675 |
# File 'lib/syntax_tree.rb', line 673 def child_nodes [] end |
#format(q) ⇒ Object
677 678 679 680 681 682 683 |
# File 'lib/syntax_tree.rb', line 677 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
685 686 687 688 689 690 691 692 693 694 |
# File 'lib/syntax_tree.rb', line 685 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
696 697 698 699 700 |
# File 'lib/syntax_tree.rb', line 696 def to_json(*opts) { type: :__end__, value: value, loc: location, cmts: comments }.to_json( *opts ) end |