How does the === work in ruby?

This question already has an answer here:

  • === vs. == in Ruby

    3 answers

  • Accept only HTTPS requests in Ruby on Rails
  • Ensure that multiple variables have a different value
  • Migrating from Rails 2 to Rails 3
  • embedded document vs hash datatype in mongoid
  • How can i have rspec test for my default scope
  • Installing Ruby gems not working with Home Brew
  • Watir text box input not persisting after submitting form (resetting to previous text box input)
  • Ruby mysql gem - How to avoid datetime automatic cast to string while querying
  • 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' === String is 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; Object#=== and Module#=== are very different methods. There’s also Regexp#===, Proc#===… that also do very different things, and are also asymmetric (match against pattern, execute with parameter(s)).

    Ruby is the best programming language in the world - Ruby on Rails.