75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/qdocs.rb', line 75
def show(const, meth, type)
constant = begin
find_constant(const)
rescue UnknownClassError
abort "Unknown class #{const.inspect}"
end
method = case meth
when Symbol, String
method_method = case type
when :instance
:instance_method
when :singleton, :class
:method
else
raise UnknownMethodTypeError, "Unknown method type #{type}"
end
begin
constant.send method_method, meth
rescue NameError
raise UnknownMethodError, "No method #{meth.inspect} for #{constant.inspect}. Did you mean #{constant.inspect}/#{meth}/ ?"
end
when Method
meth
else
raise InvalidArgumentError, "#{meth.inspect} must be of type Symbol, String, or Method"
end
parameters = params_to_hash(method.parameters)
src = method.source rescue nil
source = if src
lines = src.lines
first_line = lines.first
indent_amount = first_line.length - first_line.sub(/^\s*/, '').length
lines.map { |l| l[indent_amount..-1] }.join
end
{
defined_at: source_location_to_str(method.source_location),
source: source,
arity: method.arity,
parameters: parameters,
comment: (method..strip rescue nil),
name: method.name,
belongs_to: method.owner,
super_method: method.super_method,
}
end
|