解决方法
Also,where is this code stored when I install the gem?
如果您使用Bundler,您可以执行bundle show_permalink,并将显示该gem的安装位置.这是我用pg gem做的例子:
✗ bundle show pg /Users/jasonswett/.rvm/gems/ruby-1.9.2-p320@jason/gems/pg-0.11.0
Where does this method get defined?
如果你做捆绑显示的东西,它返回一个路径 – 该方法被定义在某处. (您可以使用grep -r’def generate_permalink’/ gem / path找到所需的位置.)
How come just I can use this method all of a sudden just by installing
the gem? Is there some sort of include/require/load to initialize the
gem’s code so that it becomes accessible to the rest of the
application?
看看这部分关于Rails初始化过程的文档:
http://guides.rubyonrails.org/initialization.html#config-boot-rb
In a standard Rails application,there’s a Gemfile which declares all
dependencies of the application. config/boot.rb sets
ENV[“BUNDLE_GEMFILE”] to the location of this file,then requires
Bundler and calls Bundler.setup which adds the dependencies of the
application (including all the Rails parts) to the load path,making
them available for the application to load.
看起来像在这个过程中相当早,Rails看着你的Gemfile,并通过Bundler加载所有的宝石.所以有你的包括.