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
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.
654 655 656 657 658 |
# File 'lib/syntax_tree.rb', line 654 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
652 653 654 |
# File 'lib/syntax_tree.rb', line 652 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
649 650 651 |
# File 'lib/syntax_tree.rb', line 649 def location @location end |
#value ⇒ Object (readonly)
- String
-
the content after the script
646 647 648 |
# File 'lib/syntax_tree.rb', line 646 def value @value end |
Instance Method Details
#child_nodes ⇒ Object
660 661 662 |
# File 'lib/syntax_tree.rb', line 660 def child_nodes [] end |
#format(q) ⇒ Object
664 665 666 667 668 669 670 |
# File 'lib/syntax_tree.rb', line 664 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
672 673 674 675 676 677 678 679 680 681 |
# File 'lib/syntax_tree.rb', line 672 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
683 684 685 686 687 |
# File 'lib/syntax_tree.rb', line 683 def to_json(*opts) { type: :__end__, value: value, loc: location, cmts: comments }.to_json( *opts ) end |