Bundler.require(*Rails.groups(:assets => %w(development test)))

This line:

  Bundler.require(*Rails.groups(:assets => %w(development test)))

from config/application.rb, i.e. 

if defined?(Bundler)

  # If you precompile assets before deploying to production, use this line

  Bundler.require *Rails.groups(:assets => %w(development test))

  # If you want your assets lazily compiled in production, use this line

  # Bundler.require(:default, :assets, Rails.env)

end

…can look a bit hairy if you’re new to Ruby / Rails.

Breaking it down:

1. The splat operator (*) breaks out the array.

E.g. 

print Rails.groups

[:default, “development”] => nil 

2.0.0p195 :006 > print *Rails.groups

defaultdevelopment => nil 

More on the splat operator here:

http://endofline.wordpress.com/2011/01/21/the-strange-ruby-splat/

2. The %w defines an array

i.e. this 

%w(foo bar) 

is shorthand for an array of strings like this:

[“foo”, “bar”]

http://stackoverflow.com/questions/1274675/ruby-what-does-warray-mean

Note that: %w is slightly different from %W

http://stackoverflow.com/questions/690794/ruby-arrays-w-vs-w?lq=1

3. The colon operator (i.e. :assets) is a symbol

i.e. 

:assets => (“development”, “test”)

Symbols are different from strings in that any two symbols named the same are identical:

“foo”.equal? “foo”  # false

:foo.equal? :foo    # true

http://stackoverflow.com/questions/6337897/what-is-the-colon-operator-in-ruby

——-

Supporting links:

More on how the assets group is handled here:

http://stackoverflow.com/questions/7351607/how-is-the-assets-group-in-rails-3-1-handled-by-bundler

and more on the Rails/Bundler precompile vs lazy compile here:

http://stackoverflow.com/questions/7673988/rails-bundler-precompile-vs-lazy-compile/7675331#7675331

Leave a Reply

Your email address will not be published. Required fields are marked *