Class: RubyVM::AbstractSyntaxTree::Node

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

Instance Method Summary collapse

Instance Method Details

#pretty_print(q) ⇒ Object



547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
# File 'lib/pp.rb', line 547

def pretty_print(q)
  q.group(1, "(#{type}@#{first_lineno}:#{first_column}-#{last_lineno}:#{last_column}", ")") {
    case type
    when :SCOPE
      pretty_print_children(q, %w"tbl args body")
    when :ARGS
      pretty_print_children(q, %w[pre_num pre_init opt first_post post_num post_init rest kw kwrest block])
    when :DEFN
      pretty_print_children(q, %w[mid body])
    when :ARYPTN
      pretty_print_children(q, %w[const pre rest post])
    when :HSHPTN
      pretty_print_children(q, %w[const kw kwrest])
    else
      pretty_print_children(q)
    end
  }
end

#pretty_print_children(q, names = []) ⇒ Object



534
535
536
537
538
539
540
541
542
543
544
545
# File 'lib/pp.rb', line 534

def pretty_print_children(q, names = [])
  children.zip(names) do |c, n|
    if n
      q.breakable
      q.text "#{n}:"
    end
    q.group(2) do
      q.breakable
      q.pp c
    end
  end
end