Class: Prism::NodeInspector
| Relationships & Source Files | |
| Inherits: | Object | 
| Defined in: | lib/prism/node_inspector.rb | 
Overview
This object is responsible for generating the output for the inspect method implementations of child nodes.
Class Method Summary
- .new(prefix = "") ⇒ NodeInspector constructor
Instance Attribute Summary
Instance Method Summary
- 
    
      #<<(line)  
    
    Appends a line to the output with the current prefix. 
- 
    
      #child_inspector(append)  
    
    Returns a new inspector that can be used to inspect a child node. 
- 
    
      #child_node(node, append)  
    
    Generates a string that represents a child node. 
- 
    
      #header(node)  
    
    This generates a string that is used as the header of the inspect output for any given node. 
- 
    
      #list(prefix, nodes)  
    
    Generates a string that represents a list of nodes. 
- 
    
      #location(value)  
    
    Generates a string that represents a location field on a node. 
- 
    
      #to_str  
    
    Returns the output as a string. 
Constructor Details
    .new(prefix = "")  ⇒ NodeInspector 
  
Instance Attribute Details
#output (readonly)
[ GitHub ]# File 'lib/prism/node_inspector.rb', line 7
attr_reader :prefix, :output
#prefix (readonly)
[ GitHub ]# File 'lib/prism/node_inspector.rb', line 7
attr_reader :prefix, :output
Instance Method Details
#<<(line)
Appends a line to the output with the current prefix.
#child_inspector(append)
Returns a new inspector that can be used to inspect a child node.
#child_node(node, append)
Generates a string that represents a child node.
# File 'lib/prism/node_inspector.rb', line 54
def child_node(node, append) node.inspect(child_inspector(append)).delete_prefix(prefix) end
#header(node)
This generates a string that is used as the header of the inspect output for any given node.
# File 'lib/prism/node_inspector.rb', line 21
def header(node) output = +"@ #{node.class.name.split("::").last} (" output << "location: (#{node.location.start_line},#{node.location.start_column})-(#{node.location.end_line},#{node.location.end_column})" output << ", newline: true" if node.newline? output << ")\n" output end
#list(prefix, nodes)
Generates a string that represents a list of nodes. It handles properly using the box drawing characters to make the output look nice.
# File 'lib/prism/node_inspector.rb', line 31
def list(prefix, nodes) output = +"(length: #{nodes.length})\n" last_index = nodes.length - 1 nodes.each_with_index do |node, index| pointer, preadd = (index == last_index) ? ["└── ", " "] : ["├── ", "│ "] node_prefix = "#{prefix}#{preadd}" output << node.inspect(NodeInspector.new(node_prefix)).sub(node_prefix, "#{prefix}#{pointer}") end output end
#location(value)
Generates a string that represents a location field on a node.
# File 'lib/prism/node_inspector.rb', line 45
def location(value) if value "(#{value.start_line},#{value.start_column})-(#{value.end_line},#{value.end_column}) = #{value.slice.inspect}" else "∅" end end
#to_str
Returns the output as a string.
# File 'lib/prism/node_inspector.rb', line 64
def to_str output end