Created
April 23, 2012 03:25
-
-
Save coreyti/2468664 to your computer and use it in GitHub Desktop.
`defined?` as conditional expression in two rubies
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
# ruby 1.8.7 | |
if defined? THOUGHT ; defined?(self) ; end # returns nil | |
if defined? THOUGHT && THINK ; defined?(self) ; end # returns nil | |
if defined?(THOUGHT) && THINK ; defined?(self) ; end # returns nil | |
if defined?(THOUGHT && THINK) ; defined?(self) ; end # returns nil | |
defined?(THOUGHT && THINK) # returns nil | |
# ruby 1.9.3 | |
if defined? THOUGHT ; defined?(self) ; end # returns nil | |
if defined? THOUGHT && THINK ; defined?(self) ; end # returns "self" | |
if defined?(THOUGHT) && THINK ; defined?(self) ; end # returns nil | |
if defined?(THOUGHT && THINK) ; defined?(self) ; end # returns "self" | |
defined?(THOUGHT && THINK) # returns "expression" | |
# hmm... it occurs to me that i'm being a bit too cute above. | |
# an example of where this might be a real issue follows. | |
# from the oauth-plugin lib at https://github.com/pelle/oauth-plugin: | |
if defined? OAUTH_10_SUPPORT && OAUTH_10_SUPPORT | |
# do OAuth 1.0 stuff (maybe not in ruby 1.8, but **always** in 1.9) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment