Class: ASTree::PrettyNode

Inherits:
Object
  • Object
show all
Defined in:
lib/astree/pretty_node.rb

Defined Under Namespace

Classes: ARGS, ARRAY, ATTRASGN, BACK_REF, BEGIN, BLOCK, BLOCK_PASS, BREAK, CALL, CASE2, CDECL, CLASS, COLON2, COLON3, CONST, CVAR, CVASGN, DASGN, DASGN_CURR, DEFN, DEFS, DREGX, DSTR, DSYM, DVAR, DXSTR, FCALL, GASGN, GVAR, HASH, IASGN, IF, IVAR, KW_ARG, LASGN, LIT, LVAR, MASGN, MATCH, NEXT, NTH_REF, OPCALL, OPT_ARG, OP_ASGN1, OP_ASGN2, OP_ASGN_AND, OP_ASGN_OR, OP_CDECL, QCALL, RESBODY, RESCUE, RETURN, SCOPE, STR, SUPER, UNLESS, VALIAS, VALUES, VCALL, WHEN, XSTR, YIELD

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ PrettyNode

Returns a new instance of PrettyNode.



5
6
7
# File 'lib/astree/pretty_node.rb', line 5

def initialize(node)
  @node = node
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



3
4
5
# File 'lib/astree/pretty_node.rb', line 3

def node
  @node
end

Instance Method Details

#element_value(index) ⇒ Object



19
20
21
# File 'lib/astree/pretty_node.rb', line 19

def element_value(index)
  node.children[index]
end

#label_name(index) ⇒ Object

Raises:

  • (NotImplementedError)


23
24
25
# File 'lib/astree/pretty_node.rb', line 23

def label_name(index)
  raise NotImplementedError
end

#stringify_element(index) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/astree/pretty_node.rb', line 9

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