Class: Prism::Node
- Inherits:
-
Object
- Object
- Prism::Node
- Defined in:
- lib/prism/node.rb,
ext/prism/extension.c
Overview
This represents a node in the tree. It is the parent class of all of the various node types.
Instance Attribute Summary collapse
-
#location ⇒ Object
readonly
A Location instance that represents the location of this node in the source.
Instance Method Summary collapse
-
#newline? ⇒ Boolean
:nodoc:.
-
#pretty_print(q) ⇒ Object
Similar to inspect, but respects the current level of indentation given by the pretty print object.
-
#set_newline_flag(newline_marked) ⇒ Object
:nodoc:.
-
#slice ⇒ Object
Slice the location of the node from the source.
-
#to_dot ⇒ Object
Convert this node into a graphviz dot graph string.
Instance Attribute Details
#location ⇒ Object (readonly)
A Location instance that represents the location of this node in the source.
14 15 16 |
# File 'lib/prism/node.rb', line 14 def location @location end |
Instance Method Details
#newline? ⇒ Boolean
:nodoc:
16 17 18 |
# File 'lib/prism/node.rb', line 16 def newline? # :nodoc: @newline ? true : false end |
#pretty_print(q) ⇒ Object
Similar to inspect, but respects the current level of indentation given by the pretty print object.
35 36 37 38 39 40 |
# File 'lib/prism/node.rb', line 35 def pretty_print(q) q.seplist(inspect.chomp.each_line, -> { q.breakable }) do |line| q.text(line.chomp) end q.current_group.break end |
#set_newline_flag(newline_marked) ⇒ Object
:nodoc:
20 21 22 23 24 25 26 |
# File 'lib/prism/node.rb', line 20 def set_newline_flag(newline_marked) # :nodoc: line = location.start_line unless newline_marked[line] newline_marked[line] = true @newline = true end end |
#slice ⇒ Object
Slice the location of the node from the source.
29 30 31 |
# File 'lib/prism/node.rb', line 29 def slice location.slice end |
#to_dot ⇒ Object
Convert this node into a graphviz dot graph string.
43 44 45 |
# File 'lib/prism/node.rb', line 43 def to_dot DotVisitor.new.tap { |visitor| accept(visitor) }.to_dot end |