diff --git a/ChangeLog b/ChangeLog index 4ebb106b4e..731831f75f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Tue Apr 24 14:54:03 2012 Nobuyoshi Nakada + + * lib/optparse.rb (OptionParser#to_a): String#to_a is no longer + defined. [ruby-dev:45568][Bug #6348] + Tue Apr 24 12:46:50 2012 Marc-Andre Lafortune * hash.c, object.c, struct.c, lib/ostruct.rb: add to_h methods. diff --git a/lib/optparse.rb b/lib/optparse.rb index a448459d46..75c6b76bc6 100644 --- a/lib/optparse.rb +++ b/lib/optparse.rb @@ -1065,13 +1065,13 @@ XXX # # Returns option summary string. # - def help; summarize(banner.to_s.sub(/\n?\z/, "\n")) end + def help; summarize("#{banner}".sub(/\n?\z/, "\n")) end alias to_s help # # Returns option summary list. # - def to_a; summarize(banner.to_a.dup) end + def to_a; summarize([*banner]) end # # Checks if an argument is given twice, in which case an ArgumentError is diff --git a/test/optparse/test_summary.rb b/test/optparse/test_summary.rb index 0c67d7f0f9..bda3b49890 100644 --- a/test/optparse/test_summary.rb +++ b/test/optparse/test_summary.rb @@ -18,4 +18,21 @@ class TestOptionParser::SummaryTest < TestOptionParser assert_match(/description 2/, s[1]) assert_match(/last-option/, s[-1]) end + + def test_banner + o = OptionParser.new("foo bar") + assert_equal("foo bar", o.banner) + end + + def test_banner_from_progname + o = OptionParser.new + o.program_name = "foobar" + assert_equal("Usage: foobar [options]\n", o.help) + end + + def test_summary + o = OptionParser.new("foo bar") + assert_equal("foo bar\n", o.to_s) + assert_equal(["foo bar"], o.to_a) + end end