Created
December 14, 2009 20:09
-
-
Save mikewadhera/256377 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Seen lots of code that uses === in favor of is_a? to do type checking | |
# Just discovered a subtle bug from the lack of symmetry of this method | |
irb(main):001:0> String === "Foo" | |
=> true | |
irb(main):002:0> "Foo" === String | |
=> false | |
# May not seem intuitive at first but the ordering is significant because === is a method! | |
# The first uses Class#=== and the second uses String#===, only the former has the type checking semantics |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment