Skip to content

Instantly share code, notes, and snippets.

@ryan-allen
Created January 23, 2009 00:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ryan-allen/50818 to your computer and use it in GitHub Desktop.
Save ryan-allen/50818 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:
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