module Rails

def groups(*groups)

# => [:default, "production"] for Rails.env == "production"
# => [:default, "development", :assets] for Rails.env == "development"
Rails.groups assets: [:development, :test]

* The optional envs given as argument and the hash with group dependencies;
* The environment variable RAILS_GROUPS;
* The Rails environment;

Returns all Rails groups for loading based on:
def groups(*groups)
  hash = groups.extract_options!
  env = Rails.env
  groups.unshift(:default, env)
  groups.concat ENV["RAILS_GROUPS"].to_s.split(",")
  groups.concat hash.map { |k, v| k if v.map(&:to_s).include?(env) }
  groups.compact!
  groups.uniq!
  groups
end