summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS3
-rw-r--r--lib/set.rb2
-rw-r--r--test/test_set.rb11
3 files changed, 16 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index aae7b96..af11da3 100644
--- a/NEWS
+++ b/NEWS
@@ -110,6 +110,9 @@ with all sufficient information, see the ChangeLog file or Redmine
* 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]
diff --git a/lib/set.rb b/lib/set.rb
index 43c388c..bfa37d4 100644
--- a/lib/set.rb
+++ b/lib/set.rb
@@ -569,6 +569,8 @@ class Set
end
end
+ alias to_s inspect
+
def pretty_print(pp) # :nodoc:
pp.text sprintf('#<%s: {', self.class.name)
pp.nest(1) {
diff --git a/test/test_set.rb b/test/test_set.rb
index 5774af7..aaf3bfe 100644
--- a/test/test_set.rb
+++ b/test/test_set.rb
@@ -715,6 +715,17 @@ class TC_Set < Test::Unit::TestCase
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"