the crack of doom on the hydrogen jukebox
And, also:>> [1,2].eql? [1,2]=> trueWTF, mate?
How about this one:>> 'a' === String=> false>> String === 'a'=> true
.eql? is an .equal? only relevant to numeric comparison.
[1,2] == [2,1] #=> false on my machine
=== is not commutative petrik. That's by design, since its main use is for the case... when statement.brian, [1,2] and [2,1] are obviously not equal. Order is meaningful in arrays.
One of them is a *by value* comparison, and one of them is a *by reference* comparison; Matz's ripped this straight out of Lisp (but Java/C# has this too).'==' is saying "Do these objects have the same value?", and 'equal?' is saying "Are these two the same object in memory". Since they were created in separate parts of the expression, and they aren't memoized, the latter is False (internally, these two arrays are stored in different places).If you picked non-integral types, '==' will always be the same as 'equal?'.
Ah ok that makes sense. Thanks!
Here is nice catch:require 'ostruct'[1, 2].to_set == [2, 1].to_set=> true
Note: Only a member of this blog may post a comment.