Created
January 23, 2009 00:47
-
-
Save ryan-allen/50818 to your computer and use it in GitHub Desktop.
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
# I don't tend to like writing this kind of code: | |
if Rails.env == 'development' or Rails.env == 'staging' | |
# ... | |
end | |
# So, an alternative Ruby way to do this is: | |
if %w(development staging).include?(Rails.env) | |
# ... | |
end | |
# But, it seems that the target is on the wrong side, reads funny, so, check this: | |
class Object | |
def in?(*array) | |
array.include?(self) | |
end | |
end | |
# Then we can write: | |
if Rails.env.in?('development', 'staging') | |
# ... | |
end | |
# Seems much nicer! What do you'se reckon? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment