-5

Possible Duplicate:
=== vs. == in Ruby

Can I assume they are the same?

if foo == "bar"

vs

if foo === "bar"

Thanks.

Community
  • 1
  • 1
Howard
  • 19,215
  • 35
  • 112
  • 184

1 Answers1

-2

They are not the same. The short answer is that == checks if the values are the same, but type-casts if necessary. === is only true if the values AND types are the same.

0 == "0" #=> true
0 === "0" #=> false
0 === 0 #=> true

There are (literally) millions of discussions about this on the internet, as this is not, by a long-shot, a Ruby-specific thing. Try a Google search if you'd like more information.

Edit

I made a mistake, this is incorrect.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
bricker
  • 8,911
  • 2
  • 44
  • 54
  • 5
    -1, `0 == "0" # => false` in Ruby. You confuse `===` with exact equality operator in JavaScript and other languages. In Ruby this is different! See the link by Greg Hewgill, he posted it 1 hour before you answered. – Aliaksei Kliuchnikau Feb 10 '12 at 10:41