If i have a gem 'foo' (Which is engine-based), how can i say that all files included in it will need the 'foo/' prefix when 'require'开发者_如何学Going them?
For instance, if in my 'foo' gem i have a 'bar.rb' file, i'd like to be able to force that the inclusion of this file are done like this:
require 'foo/bar'
instead of the usual
require 'bar'
i want this behavior to apply whatever the inclusion context is (From an APP, from another gem, etc)...
i know it's doable since most of rails files are included through the 'rails' prefix:
require 'rails/something'
You can't do that programatically other than manually specifying the prefix manually when the files are required. There's no way for Ruby to know other than if you tell it.
How about this:
Dir["/path/to/directory/*.rb"].each {|file| require file }
Just make sure you have your foo
in the root directory and the rest of the files in the subdirectory (otherwise it'll include itself)
精彩评论