How does the === work in ruby?
This question already has an answer here:
=== vs. == in Ruby
- Matching and Routes in Rails
- Active Admin date filter date format customisation
- What to use instead of `render :text` (and `render nothing: true`) in rails 5.1 and later?
- Match sequences of consecutive characters in a string
- Rails 3.1: Problem saving record with not-null boolean mysql column (false saves as NULL)
- Sinatra, MongoMapper, and Builder wrong number of arguments (1 for 0)
One Solution collect form web for “How does the === work in ruby?”
String === 'a'is the same as
String.===('a'), which calls
Class#===, inherited from
Module#===to test whether the parameter inherits from the receiver module; and
'a' === Stringis the same as
'a'.===(String), which calls
String#===, inherited from
Object#===to test whether the parameter is equal to the receiver object.
In other words,
=== is not symmetric;
Module#=== are very different methods. There’s also
Proc#===… that also do very different things, and are also asymmetric (match against pattern, execute with parameter(s)).