-1
'hello'.class == String # => true
'hello'.class === String # => false
'hello'.class.equal? String # => true

As far as I know, the equal? method has the strictest comparison test. Can someone explain why === returns false while equal? returns true here?

Dima Knivets
  • 2,418
  • 7
  • 28
  • 40

1 Answers1

1

The === for classes if defined as 'is the class of' (including classes up the hierarchy). For example:

String === 'foo' # => true
Class === String # => true
'bar'.class === 'baz' # => true

class A; end
class B < A; end
A === B.new # => true
ndnenkov
  • 35,425
  • 9
  • 72
  • 104