===(p1) public

Case Equality—Used in case statements.

a = "HELLO"
case a
when /^[a-z]*$/; print "Lower case\n"
when /^[A-Z]*$/; print "Upper case\n"
else;            print "Mixed case\n"
end
#=> "Upper case"

Following a regular expression literal with the #=== operator allows you to compare against a String.

/^[a-z]*$/ === "HELLO" #=> false
/^[A-Z]*$/ === "HELLO" #=> true
Show source
Register or log in to add new notes.
January 4, 2016 - (>= v1_9_3_392)
0 thanks

Also implemented by other classes

It’s worth noting that this method is also implemented by other classes like Proc, Range and even String.

Most of these are missing proper examples, but you can find some useful examples here:

http://www.blackbytes.info/2015/10/ruby-case/