Skip to content

Instantly share code, notes, and snippets.

@joho
Forked from ryan-allen/gist:50818
Created January 23, 2009 00:56
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 joho/50822 to your computer and use it in GitHub Desktop.
Save joho/50822 to your computer and use it in GitHub Desktop.
# 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