Skip to content

Instantly share code, notes, and snippets.

@mikewadhera
Created December 14, 2009 20:09
Show Gist options
  • Save mikewadhera/256377 to your computer and use it in GitHub Desktop.
Save mikewadhera/256377 to your computer and use it in GitHub Desktop.
# 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