Created
January 4, 2012 03:11
-
-
Save benders/1558293 to your computer and use it in GitHub Desktop.
Prevent accidentally calling #[] on a number
This file contains hidden or 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
# Prevent accidentally calling #[] on a number, we don't bit-slice in this house | |
[Fixnum, Bignum].each do |k| | |
k.class_eval do | |
def [](*args) | |
raise NoMethodError, "Calling #[] on numbers is wrong. Don't do it." | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment