Skip to content

Instantly share code, notes, and snippets.

@tpo
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tpo/11397855 to your computer and use it in GitHub Desktop.
Save tpo/11397855 to your computer and use it in GitHub Desktop.
define? considered evil
#!/usr/bin/ruby
# tested with ruby 1.9.3p194
puts "this will not print" if defined?(x)
if false
puts "this neither"
x = "foobar"
end
puts "why will x be defined here?" if defined?(x)
# Apparently because a variable gets defined when the
# *parser* sees it and *not* when it's assigned-
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment