diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/optparse.rb | 9 | ||||
-rw-r--r-- | lib/optparse/date.rb | 2 | ||||
-rw-r--r-- | lib/optparse/version.rb | 14 |
3 files changed, 19 insertions, 6 deletions
diff --git a/lib/optparse.rb b/lib/optparse.rb index 5281dbbbd7..83f2f7bdcc 100644 --- a/lib/optparse.rb +++ b/lib/optparse.rb @@ -620,7 +620,7 @@ Default options, which never appear in option summary. end end unless pkg - puts v if v = ARGV.options.ver + v = ARGV.options.ver and puts v end exit end @@ -860,11 +860,12 @@ Default options, which never appear in option summary. end =begin ---- OptionParser#to_str +--- OptionParser#help --- OptionParser#to_s Returns option summary string. =end #'#"#`# - def to_s; summarize(banner.to_s.sub(/\n?\z/, "\n")) end + def help; summarize(banner.to_s.sub(/\n?\z/, "\n")) end + alias to_s help =begin --- OptionParser#to_a @@ -976,7 +977,7 @@ Default options, which never appear in option summary. raise ArgumentError, "argument pattern given twice" end if Array === o - o.each {|o| pattern[(Array === o ? o.shift : o)] = o} + o.each {|o| pattern[(Array === o ? o[0] : o)] = o} else pattern.update(o) end diff --git a/lib/optparse/date.rb b/lib/optparse/date.rb index c9f072f290..d680559f37 100644 --- a/lib/optparse/date.rb +++ b/lib/optparse/date.rb @@ -10,7 +10,7 @@ OptionParser.accept(DateTime) do |s,| end OptionParser.accept(Date) do |s,| begin - DateTime.parse(s) if s + Date.parse(s) if s rescue ArgumentError raise OptionParser::InvalidArgument, s end diff --git a/lib/optparse/version.rb b/lib/optparse/version.rb index 35152181b0..8a1efcdf8c 100644 --- a/lib/optparse/version.rb +++ b/lib/optparse/version.rb @@ -5,7 +5,9 @@ class << OptionParser progname = ARGV.options.program_name show = proc do |klass, version| version = version.join(".") if Array === version - str = "#{progname}: #{klass} version #{version}" + str = "#{progname}" + str << ": #{klass}" unless klass == Object + str << " version #{version}" if klass.const_defined?(:Release) str << " (#{klass.const_get(:Release)})" end @@ -27,6 +29,16 @@ class << OptionParser 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 |