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
60
61
62
63
64
65
66
67
|
# File 'lib/devel/which/forobject.rb', line 33
def whereis_library(lib, opt = {})
unless lib.is_a? String
raise TypeError,
"wrong argument type #{lib.type} (expected String)"
end
unless opt.is_a? Hash
raise TypeError,
"wrong argument type #{lib.type} (expected Hash)"
end
optpath = opt[:path] || opt[:p] || []
optext = opt[:ext] || opt[:e] || ""
ext = ["rb", RbConfig::CONFIG["DLEXT"], RbConfig::CONFIG["DLEXT2"], optext]
ext.map!{|i| i.length > 0 ? ".#{i}" : nil}
ext.compact!
ext.push("")
at = []
($: + optpath).each{|path|
with = nil
file = "#{File::expand_path(path)}/#{lib}"
begin
ext.each{|with|
if (test(?f, file+with) && test(?r, file+with) rescue false)
at << "#{path}/#{lib}#{with}"
end
}
rescue
next
end
}
at
end
|