Created
April 26, 2012 15:07
-
-
Save mikekreeki/2500255 to your computer and use it in GitHub Desktop.
multiple require refactorings
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
require 'nokogiri' | |
require 'active_support' | |
require 'benchmark' | |
# equal to... | |
list = ['nokogiri', 'active_support', 'benchmark'] | |
## never use `for` cycle (unless you know exactly why), it's considered a bad practice, | |
## you save one method call since `for` calls `each` method internally anyway | |
for x in list | |
require x | |
end | |
# equal to... | |
['nokogiri', 'active_support', 'benchmark'].each do |x| | |
require x | |
end | |
# equal to... | |
['nokogiri', 'active_support', 'benchmark'].each {|x| require x} | |
# equal to... | |
['nokogiri', 'active_support', 'benchmark'].each &method(:require) | |
# equal to... | |
%w(nokogiri active_support benchmark).each &method(:require) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment