|
6 | 6 |
|
7 | 7 | module IRB # :nodoc: |
8 | 8 |
|
9 | | - |
10 | 9 | # Convenience method to create a new Inspector, using the given +inspect+ |
11 | 10 | # proc, and optional +init+ proc and passes them to Inspector.new |
12 | 11 | # |
@@ -43,38 +42,40 @@ class Inspector |
43 | 42 | # +:marshal+:: Using Marshal.dump |
44 | 43 | INSPECTORS = {} |
45 | 44 |
|
46 | | - # Determines the inspector to use where +inspector+ is one of the keys passed |
47 | | - # during inspector definition. |
48 | | - def self.keys_with_inspector(inspector) |
49 | | - INSPECTORS.select{|k, v| v == inspector}.collect{|k, v| k} |
50 | | - end |
51 | | - |
52 | | - # Example |
53 | | - # |
54 | | - # Inspector.def_inspector(key, init_p=nil){|v| v.inspect} |
55 | | - # Inspector.def_inspector([key1,..], init_p=nil){|v| v.inspect} |
56 | | - # Inspector.def_inspector(key, inspector) |
57 | | - # Inspector.def_inspector([key1,...], inspector) |
58 | | - def self.def_inspector(key, arg=nil, &block) |
59 | | - if block_given? |
60 | | - inspector = IRB::Inspector(block, arg) |
61 | | - else |
62 | | - inspector = arg |
| 45 | + class << self |
| 46 | + # Determines the inspector to use where +inspector+ is one of the keys passed |
| 47 | + # during inspector definition. |
| 48 | + def keys_with_inspector(inspector) |
| 49 | + INSPECTORS.select{|k, v| v == inspector}.collect{|k, v| k} |
63 | 50 | end |
64 | 51 |
|
65 | | - case key |
66 | | - when Array |
67 | | - for k in key |
68 | | - def_inspector(k, inspector) |
| 52 | + # Example |
| 53 | + # |
| 54 | + # Inspector.def_inspector(key, init_p=nil){|v| v.inspect} |
| 55 | + # Inspector.def_inspector([key1,..], init_p=nil){|v| v.inspect} |
| 56 | + # Inspector.def_inspector(key, inspector) |
| 57 | + # Inspector.def_inspector([key1,...], inspector) |
| 58 | + def def_inspector(key, arg=nil, &block) |
| 59 | + if block_given? |
| 60 | + inspector = IRB::Inspector(block, arg) |
| 61 | + else |
| 62 | + inspector = arg |
| 63 | + end |
| 64 | + |
| 65 | + case key |
| 66 | + when Array |
| 67 | + for k in key |
| 68 | + def_inspector(k, inspector) |
| 69 | + end |
| 70 | + when Symbol |
| 71 | + INSPECTORS[key] = inspector |
| 72 | + INSPECTORS[key.to_s] = inspector |
| 73 | + when String |
| 74 | + INSPECTORS[key] = inspector |
| 75 | + INSPECTORS[key.intern] = inspector |
| 76 | + else |
| 77 | + INSPECTORS[key] = inspector |
69 | 78 | end |
70 | | - when Symbol |
71 | | - INSPECTORS[key] = inspector |
72 | | - INSPECTORS[key.to_s] = inspector |
73 | | - when String |
74 | | - INSPECTORS[key] = inspector |
75 | | - INSPECTORS[key.intern] = inspector |
76 | | - else |
77 | | - INSPECTORS[key] = inspector |
78 | 79 | end |
79 | 80 | end |
80 | 81 |
|
|
0 commit comments