Sha256: 2f19f797de0d3c836ce97264984b51f5ed75ed247e8f792692a6abe4468d739c
Contents?: true
Size: 771 Bytes
Versions: 2
Compression:
Stored size: 771 Bytes
Contents
class ASTree class PrettyNode attr_reader :node def initialize(node) @node = node end def stringify_element(index) label = label_name(index) if label.nil? raise "Unexpected index [#{index}] - #{node.inspect}." end "%s (%s)\n" % [colorize_element(element_value(index)), label] end def element_value(index) node.children[index] end def label_name(index) raise NotImplementedError end private def colorize_element(value) case value when String value.inspect.colorize(:red) when Symbol value.inspect.colorize(:yellow) when NilClass value.inspect.colorize(:cyan) else value.inspect end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
astree-1.1.1 | lib/astree/pretty_node.rb |
astree-1.1.0 | lib/astree/pretty_node.rb |