rogerdpack-desc_method 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README +48 -21
- data/lib/method_describer/method_desc.rb +5 -1
- metadata +1 -1
data/README
CHANGED
@@ -1,24 +1,21 @@
|
|
1
|
-
A "ruby
|
1
|
+
A "run time RI for ruby methods", this gem allows you to inspect objects' methods while within irb or ruby-debug. It reveals everything known about the method in question. This includes source, ri, arity, rdoc comments (on 1.9), etc. where available
|
2
2
|
|
3
|
-
For me it has proved quite useful, and I wouldn't
|
3
|
+
For me it has proved quite useful, and I wouldn't do a ruby-debug session without it--try it--you might really like it.
|
4
4
|
|
5
|
-
|
6
|
-
>>
|
7
|
-
class A;
|
5
|
+
irb examples:
|
6
|
+
>> class A;
|
8
7
|
def go(a); end;
|
9
|
-
|
8
|
+
end
|
10
9
|
>> A.desc_method :go
|
11
|
-
|
10
|
+
#<UnboundMethod: A#go> arity: 1
|
12
11
|
ri for A#go
|
13
12
|
Nothing known about A
|
14
13
|
(end ri)
|
15
|
-
|
16
|
-
A#go a
|
17
|
-
proc { |a|
|
14
|
+
def go(a)
|
18
15
|
# do nothing
|
19
|
-
|
16
|
+
end
|
17
|
+
Parameters: go(a)
|
20
18
|
|
21
|
-
an example in 1.9:
|
22
19
|
>> File.desc_method :delete
|
23
20
|
ri for File.delete
|
24
21
|
----------------------------------------------------------- File::delete
|
@@ -35,6 +32,37 @@ ri for File.delete
|
|
35
32
|
appears to be a c method
|
36
33
|
#parameters signature: delete( [[:rest]] )
|
37
34
|
|
35
|
+
|
36
|
+
Or my favorite, using it in debug sessions:
|
37
|
+
(rdb:1) l=
|
38
|
+
...
|
39
|
+
=> 74 assert(assigns['order'].order_line_items.map(:unit_price).min >= -5)
|
40
|
+
...
|
41
|
+
(rdb:1) desc_method :assert
|
42
|
+
#<Method: StoreControllerTest(Test::Unit::Assertions)#assert> arity: -2
|
43
|
+
ri for Test::Unit::Assertions#assert
|
44
|
+
------------------------------------------ Test::Unit::Assertions#assert
|
45
|
+
assert(boolean, message=nil)
|
46
|
+
|
47
|
+
From gem test-unit-2.0.1
|
48
|
+
------------------------------------------------------------------------
|
49
|
+
Asserts that +boolean+ is not false or nil.
|
50
|
+
|
51
|
+
Example:
|
52
|
+
|
53
|
+
assert [1, 2].include?(5)
|
54
|
+
|
55
|
+
(end ri)
|
56
|
+
def assert(boolean, message = nil)
|
57
|
+
_wrap_assertion do
|
58
|
+
assert_block("assert should not be called with a block.") do
|
59
|
+
(not block_given?)
|
60
|
+
end
|
61
|
+
assert_block(build_message(message, "<?> is not true.", boolean)) { boolean }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
Parameters: assert(boolean, message = nil)
|
65
|
+
|
38
66
|
========= Installation/usage:=====
|
39
67
|
Installation:
|
40
68
|
$ gem install rogerdpack-desc_method
|
@@ -45,19 +73,18 @@ Usage:
|
|
45
73
|
>> instance.desc_method :instance_method_name
|
46
74
|
...
|
47
75
|
|
48
|
-
|
49
|
-
Class
|
76
|
+
Other goodies also included:
|
77
|
+
Class#desc_class
|
50
78
|
>> Object.desc_class
|
51
|
-
# outputs RI, methods, etc.
|
52
|
-
or
|
79
|
+
# outputs descriptive info about that class--RI, methods, etc.
|
53
80
|
>> Object.desc_class :verbose => true
|
54
81
|
# outputs RI, method lists including inherited methods, ancestors, constants
|
55
82
|
|
56
|
-
Kernel#
|
57
|
-
>>
|
58
|
-
=> [:first, :second, :after_this_are_inherited>>>>>, :some_inherited_method, :another_inherited_method] # adds in
|
59
|
-
|
83
|
+
Kernel#methods is also monkey patched to output a "separator" between its inherited and non inherited methods--i.e.
|
84
|
+
>> instance.methods
|
85
|
+
=> [:first, :second, :after_this_are_inherited>>>>>, :some_inherited_method, :another_inherited_method] # adds in that separator
|
60
86
|
|
61
|
-
|
87
|
+
=== Thanks ===
|
88
|
+
This gem wraps functionality of Method#source_location, ruby2ruby, et al, and also some from manvenu, SourceRef (MBARI), and also would not be useful without ruby-debug and all the core guys. Thank you.
|
62
89
|
|
63
90
|
Comments/suggestions welcome rogerdpack on gmail or github
|
@@ -122,7 +122,11 @@ module SourceLocationDesc
|
|
122
122
|
|
123
123
|
puts doc # always output it since RI does currently [todo make optional I suppose, and non out-putty]
|
124
124
|
|
125
|
-
|
125
|
+
if want_the_description_returned # give them something they can examine
|
126
|
+
doc
|
127
|
+
else
|
128
|
+
self
|
129
|
+
end
|
126
130
|
end
|
127
131
|
|
128
132
|
named_args_for :desc # just for fun, tests use it too, plus it should actually wurk without interfering...I think
|