aboutsummaryrefslogtreecommitdiffstats
path: root/hash.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-02-13 12:45:59 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-02-13 12:45:59 +0000
commit1210ed2f24d33fb5f810baa6d74ea1aea7fa2597 (patch)
treef3121f3a823a89d67b35cf6ee87a45b3b84adfad /hash.c
parentd4931d994171e5515f091dc9c15ee403eb998a74 (diff)
downloadruby-1210ed2f24d33fb5f810baa6d74ea1aea7fa2597.tar.gz
* hash.c (rb_hash_invert): [DOC] more examples.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53818 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/hash.c b/hash.c
index 7759332a0b..68da110511 100644
--- a/hash.c
+++ b/hash.c
@@ -2217,6 +2217,22 @@ rb_hash_invert_i(VALUE key, VALUE value, VALUE hash)
* h = { "n" => 100, "m" => 100, "y" => 300, "d" => 200, "a" => 0 }
* h.invert #=> {0=>"a", 100=>"m", 200=>"d", 300=>"y"}
*
+ * If there is no key with the same value, Hash#invert is involutive.
+ *
+ * h = { a: 1, b: 3, c: 4 }
+ * h.invert.invert == h #=> true
+ *
+ * The condition, no key with the same value, can be tested by comparing
+ * the size of inverted hash.
+ *
+ * # no key with the same value
+ * h = { a: 1, b: 3, c: 4 }
+ * h.size == h.invert.size #=> true
+ *
+ * # two (or more) keys has the same value
+ * h = { a: 1, b: 3, c: 1 }
+ * h.size == h.invert.size #=> false
+ *
*/
static VALUE