[前][次][番号順一覧][スレッド一覧]

ruby-changes:47217

From: knu <ko1@a...>
Date: Fri, 14 Jul 2017 17:46:17 +0900 (JST)
Subject: [ruby-changes:47217] knu:r59332 (trunk): Alias Set#to_s to #inspect [Feature #13676]

knu	2017-07-14 17:46:13 +0900 (Fri, 14 Jul 2017)

  New Revision: 59332

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59332

  Log:
    Alias Set#to_s to #inspect [ruby-core:81753] [Feature #13676]

  Modified files:
    trunk/NEWS
    trunk/lib/set.rb
    trunk/test/test_set.rb
Index: lib/set.rb
===================================================================
--- lib/set.rb	(revision 59331)
+++ lib/set.rb	(revision 59332)
@@ -569,6 +569,8 @@ class Set https://github.com/ruby/ruby/blob/trunk/lib/set.rb#L569
     end
   end
 
+  alias to_s inspect
+
   def pretty_print(pp)  # :nodoc:
     pp.text sprintf('#<%s: {', self.class.name)
     pp.nest(1) {
Index: NEWS
===================================================================
--- NEWS	(revision 59331)
+++ NEWS	(revision 59332)
@@ -110,6 +110,9 @@ with all sufficient information, see the https://github.com/ruby/ruby/blob/trunk/NEWS#L110
   * Carriage returns are changed to be trimmed properly if trim_mode is specified
     and used. Duplicated newlines will be removed on Windows. [Bug #5339] [Bug #11464]
 
+* Set
+  * Add Set#to_s as alias to #inspect [Feature #13676]
+
 * WEBrick
 
   * Add Server Name Indication (SNI) support [Feature #13729]
Index: test/test_set.rb
===================================================================
--- test/test_set.rb	(revision 59331)
+++ test/test_set.rb	(revision 59332)
@@ -715,6 +715,17 @@ class TC_Set < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/test_set.rb#L715
     assert_equal('#<Set: {#<Set: {0}>, 1, 2, #<Set: {1, 2, #<Set: {...}>}>}>', set2.inspect)
   end
 
+  def test_to_s
+    set1 = Set[1, 2]
+    assert_equal('#<Set: {1, 2}>', set1.to_s)
+
+    set2 = Set[Set[0], 1, 2, set1]
+    assert_equal('#<Set: {#<Set: {0}>, 1, 2, #<Set: {1, 2}>}>', set2.to_s)
+
+    set1.add(set2)
+    assert_equal('#<Set: {#<Set: {0}>, 1, 2, #<Set: {1, 2, #<Set: {...}>}>}>', set2.to_s)
+  end
+
   def test_compare_by_identity
     a1, a2 = "a", "a"
     b1, b2 = "b", "b"

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]