Skip to content

Instantly share code, notes, and snippets.

@sdball
Last active March 16, 2019 01:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sdball/5162135 to your computer and use it in GitHub Desktop.
Save sdball/5162135 to your computer and use it in GitHub Desktop.
Sometimes Ruby is Weird
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!"
@sdball
Copy link
Author

sdball commented Mar 18, 2013

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment