Module: RubySpy

Defined in:
lib/rubyspy.rb

Constant Summary collapse

ALPHABET_DISP_NUM =

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

5
OPERATOR_DISP_NUM =
10

Class Method Summary collapse

Class Method Details

.p_classtree(c) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rubyspy.rb', line 17

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) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/rubyspy.rb', line 31

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