1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/lib/optparse/version.rb
nobu 73e4384a23 * lib/optparse.rb (--version): fix assignment/reference order.
* lib/optparse.rb (OptionParser#help): new; OptionParser#to_s may
  be deprecated in future.

* lib/optparse/version.rb (OptionParser#show_version): hide Object.

* test/runner.rb: fix optparse usage.

* test/runner.rb: glob all testsuits if no tests given.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4504 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-09-05 02:32:24 +00:00

53 lines
1.5 KiB
Ruby

# OptionParser internal utility
class << OptionParser
def show_version(*pkg)
progname = ARGV.options.program_name
show = proc do |klass, version|
version = version.join(".") if Array === version
str = "#{progname}"
str << ": #{klass}" unless klass == Object
str << " version #{version}"
if klass.const_defined?(:Release)
str << " (#{klass.const_get(:Release)})"
end
puts str
end
if pkg.size == 1 and pkg[0] == "all"
self.search_const(::Object, "Version", &show)
else
pkg.each do |pkg|
/\A[A-Z]\w*((::|\/)[A-Z]\w*)*\z/ni =~ pkg or next
begin
pkg = eval(pkg)
show.call(pkg, pkg.const_defined?(:Version) ? pkg.const_get(:Version) : "unknown")
rescue NameError
puts "#{progname}: #$!"
end
end
end
exit
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, const if cname == name
klasses << const if Module === const and const != ::Object
end
end
end
end