Skip to content

Commit

Permalink
Add Set#=== as alias to Set#includes? (#5269)
Browse files Browse the repository at this point in the history
* Add `Set#===` as alias to `Set#includes?`

This method is for convenience with using on `case` statement.

Ruby 2.5 decides such a change, this commit follows it:
https://bugs.ruby-lang.org/issues/13801

* Fix doc text for Set#=== as like Range#===
  • Loading branch information
makenowjust authored and bcardiff committed Nov 27, 2017
1 parent 3f06d20 commit 6ee1bf9
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/set.cr
Expand Up @@ -276,6 +276,29 @@ struct Set(T)
same?(other) || @hash == other.@hash
end

# Same as `#includes?`.
#
# It is for convenience with using on `case` statement.
#
# ```
# red_like = Set{"red", "pink", "violet"}
# blue_like = Set{"blue", "azure", "violet"}
#
# case "violet"
# when red_like & blue_like
# puts "red & blue like color!"
# when red_like
# puts "red like color!"
# when blue_like
# puts "blue like color!"
# end
# ```
#
# See also: `Object#===`.
def ===(object : T)
includes? object
end

# Returns a new `Set` with all of the same elements.
def dup
Set.new(self)
Expand Down

0 comments on commit 6ee1bf9

Please sign in to comment.