Created
June 11, 2014 19:44
-
-
Save juliandunn/4e4d9b52136815279808 to your computer and use it in GitHub Desktop.
Monkeypatching NilClass to clarify what the heck is meant by "NoMethodError: undefined method `[]' for nil:NilClass"
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
class NilClass | |
def [] | |
raise "What the hell, dawg, you can't access an element of nil" | |
end | |
def [](a) | |
raise "What the hell, dawg, you can't access element #{a} of nil" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment