Last active
March 16, 2019 01:35
-
-
Save sdball/5162135 to your computer and use it in GitHub Desktop.
Sometimes Ruby is Weird
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
class NilWhatAreYouDoingStahp | |
attr_accessor :not_nil | |
def initialize | |
@not_nil = "I'm not nil! I'm a value!" | |
end | |
def wat | |
if not_nil.nil? | |
not_nil = "Ok, now I'm not nil." | |
end | |
not_nil | |
end | |
def omglol | |
not_nil | |
end | |
end | |
stahp = NilWhatAreYouDoingStahp.new | |
stahp.wat # => nil | |
stahp.omglol # => "I'm not nil! I'm a value!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Spot on! Another fun way to present this puzzle is to say that adding five characters makes the code work as expected. That's almost a giveaway though.