1 # OptionParser internal utility
5 progname = ARGV.options.program_name
7 show = proc do |klass, cname, version|
9 unless klass == ::Object and cname == :VERSION
10 version = version.join(".") if Array === version
11 str << ": #{klass}" unless klass == Object
12 str << " version #{version}"
14 [:Release, :RELEASE].find do |rel|
15 if klass.const_defined?(rel)
16 str << " (#{klass.const_get(rel)})"
22 if pkg.size == 1 and pkg[0] == "all"
23 self.search_const(::Object, /\AV(?:ERSION|ersion)\z/) do |klass, cname, version|
24 unless cname[1] == ?e and klass.const_defined?(:Version)
25 show.call(klass, cname.intern, version)
31 pkg = pkg.split(/::|\//).inject(::Object) {|m, c| m.const_get(c)}
33 when pkg.const_defined?(:Version)
34 pkg.const_get(n = :Version)
35 when pkg.const_defined?(:VERSION)
36 pkg.const_get(n = :VERSION)
49 def each_const(path, klass = ::Object)
50 path.split(/::|\//).inject(klass) do |klass, name|
51 raise NameError, path unless Module === klass
52 klass.constants.grep(/#{name}/i) do |c|
53 klass.const_defined?(c) or next
54 c = klass.const_get(c)
59 def search_const(klass, name)
61 while klass = klasses.shift
62 klass.constants.each do |cname|
63 klass.const_defined?(cname) or next
64 const = klass.const_get(cname)
65 yield klass, cname, const if name === cname
66 klasses << const if Module === const and const != ::Object