aboutsummaryrefslogtreecommitdiffstats
path: root/lib/set.rb
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-19 08:45:12 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-19 08:45:12 +0000
commit1b34da0d79ff2e55d7e119657b0f913bb762533b (patch)
tree3ea77cd20f5e90e98356845e8dbda006bc8d9f48 /lib/set.rb
parent72e090cad879e601fdf5d1c3cb2e9fbee536bf2a (diff)
downloadruby-1b34da0d79ff2e55d7e119657b0f913bb762533b.tar.gz
Alias Set#=== to #include?
* set.rb (Set#===): Added via [Feature #13801] by davidarnold. Closes #1673. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59966 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/set.rb')
-rw-r--r--lib/set.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/set.rb b/lib/set.rb
index bfa37d4dc0..009721381b 100644
--- a/lib/set.rb
+++ b/lib/set.rb
@@ -475,6 +475,23 @@ class Set
@hash.eql?(o.instance_variable_get(:@hash))
end
+ # Returns true if obj is a member of the set, and false otherwise.
+ #
+ # Used in case statements:
+ #
+ # case :apple
+ # when Set[:potato, :carrot] then 'vegetable'
+ # when Set[:apple, :banana] then 'fruit'
+ # end
+ # #=> "fruit"
+ #
+ # Or by itself:
+ #
+ # Set[1, 2, 3] === 2 #=> true
+ # Set[1, 2, 3] === 4 #=> false
+ #
+ alias === include?
+
# Classifies the set by the return value of the given block and
# returns a hash of {value => set of elements} pairs. The block is
# called once for each element of the set, passing the element as