This question already has an answer here:
- How can I debug require in Ruby 1.9 1 answer
I got interested in Rubygem, and started to explore how does it works, and found out that after 1.9, Rubygem's require
became THE require
.
With the code below:
require 'debugger'
debugger
require 'thor'
I started to n
and l
and s
, but got stuck at:
# specification.rb:263
def self._all # :nodoc:
unless defined?(@@all) && @@all then
specs = {}
self.dirs.each { |dir|
Dir[File.join(dir, "*.gemspec")].each { |path|
spec = Gem::Specification.load path.untaint
# #load returns nil if the spec is bad, so we just ignore
# it at this stage
specs[spec.full_name] ||= spec if spec
}
}
@@all = specs.values
_resort!
end
@@all
end
It seems that before stepping into the method above, @@all
has already be been prepared. Then I set break-points everywhere @@all =
, but none of the break-points are reached.
What am i missing???
EDIT:
Look at my question again. See require 'debugger'
? I feel like a fool.
Now the question is "How can I debug require
"?
CLOSED:
Plz see this great answer:https://stackoverflow.com/a/16069229/342366
Thx again for this greet answer:https://stackoverflow.com/a/16069229/342366, i did a little debugging myself.
For some one google to this question(and lazy to debug), i decide to post the answer to "How does Rubygem require all gems?"
There are the key-steps below:
load all ".gemspec" in "Ruby193\lib\ruby\gems\1.9.1\specifications"
sort the gems by version desc
got the first gem (the higher version)
activate the gem and all dependencies~ Everyone's happy.