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
Returns the value of attribute location.
Instance Method Summary collapse
- #newline? ⇒ Boolean
-
#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
-
#slice ⇒ Object
Slice the location of the node from the source.
Instance Attribute Details
#location ⇒ Object (readonly)
Returns the value of attribute location.
12 13 14 |
# File 'lib/prism/node.rb', line 12 def location @location end |
Instance Method Details
#newline? ⇒ Boolean
14 15 16 |
# File 'lib/prism/node.rb', line 14 def newline? @newline ? true : false end |
#pretty_print(q) ⇒ Object
Similar to inspect, but respects the current level of indentation given by the pretty print object.
33 34 35 36 37 38 |
# File 'lib/prism/node.rb', line 33 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
18 19 20 21 22 23 24 |
# File 'lib/prism/node.rb', line 18 def set_newline_flag(newline_marked) 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.
27 28 29 |
# File 'lib/prism/node.rb', line 27 def slice location.slice end |