module RubySpy

Constants

ALPHABET_DISP_NUM

アルファベットと演算子で表示する数を変える

OPERATOR_DISP_NUM

Public Class Methods

p_classtree(c) click to toggle source
# File lib/rubyspy.rb, line 16
def p_classtree(c)
  unless c.is_a?(Class)
    c = c.class
  end
  
  while (true)
    puts c.name
    break if (c == Object)
    p_classtree_sub(c)
    c = c.superclass
  end
end
p_classtree_sub(c) click to toggle source
# File lib/rubyspy.rb, line 30
def p_classtree_sub(c)
  # メソッドの一覧を得る
  group = c.public_instance_methods(false).sort.partition { |m| m =~ /\w/ }
  array = group.flatten
  operator_start_index = group[0].size
  limit = ALPHABET_DISP_NUM

  print((array.size > limit) ? "|  " :  "↓  ")
  
  counter = 0
  array.each_with_index do |v, index|
    if (index == operator_start_index)
      limit = OPERATOR_DISP_NUM
      counter = 0
      puts
      print((array.size - index > limit) ? "|  " : "↓  ")
    end

    if (counter >= limit)
      counter = 0
      puts
      print((array.size - index > limit) ? "|  " : "↓  ")
    end

    print v + ", "
    counter += 1
  end
  puts
end

Private Instance Methods

p_classtree(c) click to toggle source
# File lib/rubyspy.rb, line 16
def p_classtree(c)
  unless c.is_a?(Class)
    c = c.class
  end
  
  while (true)
    puts c.name
    break if (c == Object)
    p_classtree_sub(c)
    c = c.superclass
  end
end
p_classtree_sub(c) click to toggle source
# File lib/rubyspy.rb, line 30
def p_classtree_sub(c)
  # メソッドの一覧を得る
  group = c.public_instance_methods(false).sort.partition { |m| m =~ /\w/ }
  array = group.flatten
  operator_start_index = group[0].size
  limit = ALPHABET_DISP_NUM

  print((array.size > limit) ? "|  " :  "↓  ")
  
  counter = 0
  array.each_with_index do |v, index|
    if (index == operator_start_index)
      limit = OPERATOR_DISP_NUM
      counter = 0
      puts
      print((array.size - index > limit) ? "|  " : "↓  ")
    end

    if (counter >= limit)
      counter = 0
      puts
      print((array.size - index > limit) ? "|  " : "↓  ")
    end

    print v + ", "
    counter += 1
  end
  puts
end