diff options
author | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-08-15 19:08:43 +0000 |
---|---|---|
committer | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-08-15 19:08:43 +0000 |
commit | d464704f111d211c1f1ff9ef23ef1d755054be00 (patch) | |
tree | b58b17b645dc463322e5fca57fe282360db659c9 /ruby_1_8_5/lib/optparse/version.rb | |
parent | e4f06b3f2dec4b5d6334c5e9907e1cecbf649fc4 (diff) |
add tag v1_8_5_54
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/tags/v1_8_5_54@12952 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ruby_1_8_5/lib/optparse/version.rb')
-rw-r--r-- | ruby_1_8_5/lib/optparse/version.rb | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/ruby_1_8_5/lib/optparse/version.rb b/ruby_1_8_5/lib/optparse/version.rb new file mode 100644 index 0000000000..558d9d710b --- /dev/null +++ b/ruby_1_8_5/lib/optparse/version.rb @@ -0,0 +1,70 @@ +# OptionParser internal utility + +class << OptionParser + def show_version(*pkg) + progname = ARGV.options.program_name + result = false + show = proc do |klass, cname, version| + str = "#{progname}" + unless klass == ::Object and cname == :VERSION + version = version.join(".") if Array === version + str << ": #{klass}" unless klass == Object + str << " version #{version}" + end + [:Release, :RELEASE].find do |rel| + if klass.const_defined?(rel) + str << " (#{klass.const_get(rel)})" + end + end + puts str + result = true + end + if pkg.size == 1 and pkg[0] == "all" + self.search_const(::Object, /\AV(?:ERSION|ersion)\z/) do |klass, cname, version| + unless cname[1] == ?e and klass.const_defined?(:Version) + show.call(klass, cname.intern, version) + end + end + else + pkg.each do |pkg| + begin + pkg = pkg.split(/::|\//).inject(::Object) {|m, c| m.const_get(c)} + v = case + when pkg.const_defined?(:Version) + pkg.const_get(n = :Version) + when pkg.const_defined?(:VERSION) + pkg.const_get(n = :VERSION) + else + n = nil + "unknown" + end + show.call(pkg, n, v) + rescue NameError + end + end + end + result + end + + def each_const(path, klass = ::Object) + path.split(/::|\//).inject(klass) do |klass, name| + raise NameError, path unless Module === klass + klass.constants.grep(/#{name}/i) do |c| + klass.const_defined?(c) or next + c = klass.const_get(c) + end + end + end + + def search_const(klass, name) + klasses = [klass] + while klass = klasses.shift + klass.constants.each do |cname| + klass.const_defined?(cname) or next + const = klass.const_get(cname) + yield klass, cname, const if name === cname + klasses << const if Module === const and const != ::Object + end + end + end +end |