Skip to content

Commit 6ee1bf9

Browse files
makenowjustbcardiff
authored andcommitted
Add Set#=== as alias to Set#includes? (#5269)
* 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#===
1 parent 3f06d20 commit 6ee1bf9

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/set.cr

+23
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,29 @@ struct Set(T)
276276
same?(other) || @hash == other.@hash
277277
end
278278

279+
# Same as `#includes?`.
280+
#
281+
# It is for convenience with using on `case` statement.
282+
#
283+
# ```
284+
# red_like = Set{"red", "pink", "violet"}
285+
# blue_like = Set{"blue", "azure", "violet"}
286+
#
287+
# case "violet"
288+
# when red_like & blue_like
289+
# puts "red & blue like color!"
290+
# when red_like
291+
# puts "red like color!"
292+
# when blue_like
293+
# puts "blue like color!"
294+
# end
295+
# ```
296+
#
297+
# See also: `Object#===`.
298+
def ===(object : T)
299+
includes? object
300+
end
301+
279302
# Returns a new `Set` with all of the same elements.
280303
def dup
281304
Set.new(self)

0 commit comments

Comments
 (0)