Created
July 8, 2015 01:09
-
-
Save fny/7ab53d4537e848075d01 to your computer and use it in GitHub Desktop.
Dry Up Your Initializers with #tap
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
# Before | |
Rails.application.config.assets.version = '1.0' | |
Rails.application.config.assets.paths << Emoji.images_path | |
Rails.application.config.assets.precompile += %w( search.js ) | |
# After | |
Rails.application.config.assets.tap do |assets| | |
assets.version = '1.0' | |
assets.paths << Emoji.images_path | |
assets.precompile += %w( search.js ) | |
end |
As a guide, it is better to be clearer.
But as a developer you can just use whatever you want :P
Great 👍
As alternative you can use instance_eval
here:
Rails.application.config.assets.instance_eval do
# 'self' here is your assets config
self.version = '1.0'
self.paths << Emoji.images_path
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's worth noting that
#tap
is very similar to#map
, which might cause confusion.