requier 引用一个文件夹下的多个文件
2015-05-26 本文已影响18人
kamionayuki
http://rubyer.me/blog/689/
参考上面的链接,基本上能满足所有的要求。
如果图省事的话,就直接用requier_all
这个gem
Installation
Gemfile:
gem 'require_all'
And then execute:bundle
Usagerequire
'require_all'
*load all ruby files in the directory "lib" and its subdirectories*
require_all 'lib'
*or load all files by using glob*
require_all 'lib/**/*.rb'
*or load files in an Array*
require_all Dir.glob("blah/**/*.rb").reject { |f| stupid_file? f }
*or load manually specified files*
require_all 'lib/a.rb', 'lib/b.rb', 'lib/c.rb', 'lib/d.rb'
You can also load files relative to the current file by using require_rel:
Instead of
require File.dirname(__FILE__) + '/foobar'
you can do simply like thisrequire_rel 'foobar'