Difference between == and === and eql? and equal? in ruby

(==) compares the value of objects and returns true/false (eql?) compares the value of objects and returns true/false

  'ashish' == 'ashish'   #=> true
  'ashish'.eql?('ashish')   #=> true

(equal?) compares the object_id and return true/false

  'ashish'.equal?('ashish')   #=> false
  1.equal?(1)   #=> true
  :ashish.equal?(:ashish)   #=> true 

(===) compares whether right hand side object belongs to the Class on left hand side or class of object on left hand side.

  'ashish' === 'ashish'  #=> true
  String === 'ashish'    #=> true
comments powered by Disqus