Skip to content

Instantly share code, notes, and snippets.

@mikekreeki
Created April 26, 2012 15:07
Show Gist options
  • Save mikekreeki/2500255 to your computer and use it in GitHub Desktop.
Save mikekreeki/2500255 to your computer and use it in GitHub Desktop.
multiple require refactorings
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