-
-
Save joho/50822 to your computer and use it in GitHub Desktop.
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
# 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: | |
# i prefer one of over in | |
class Object | |
def one_of?(*array) | |
array.include?(self) | |
end | |
end | |
# Then we can write: | |
if Rails.env.one_of? '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