2013-04-17 67 views
0

我對Rubygem感興趣,並開始研究它是如何工作的,並且發現在1.9之後,Rubygem的require成爲了requireRubygem如何需要所有寶石?

與下面的代碼:

require 'debugger' 
debugger 
require 'thor' 

我開始nls,但被困在:

# 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 

似乎步入上面的方法之前,@@all早已準備好了。然後,我在各個地方都設立了折點 - @@all =,但沒有達到任何折點。

我失蹤了什麼?


編輯:我的問題

再看看。見require 'debugger'?我覺得自己像個傻瓜。

現在的問題是「我怎樣才能調試require


CLOSED:

PLZ看到這個偉大的答案:再次https://stackoverflow.com/a/16069229/342366

+0

你是什麼意思?«我開始''和''''和''''? 「self._all」從哪裏來? –

+0

我試圖澄清你的問題,如果這不是你的問題,幫助你自己... –

+0

@BeatRichartz n && l && s next && list && step,調試器中的命令 – rhapsodyn

回答

0

THX此迎接答案:https://stackoverflow.com/a/16069229/342366,我做了一點自己的調試。

對於一個谷歌這個問題(懶惰調試),我決定發佈答案「Rubygem如何需要所有的寶石?」

有以下主要步驟:在

  1. 加載所有 「.gemspec」 「Ruby193 \ LIB \紅寶石\寶石\ 1.9.1 \規範」

    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 
    } 
    
  2. 排序通過版本遞減寶石

    @@all.sort! { |a, b| 
        names = a.name <=> b.name 
        next names if names.nonzero? 
        b.version <=> a.version 
    } 
    
  3. 拿到了首批創業板(高版本)

    self.find { |spec| 
        spec.contains_requirable_file? path 
    } 
    
  4. 激活寶石和所有的依賴〜大家都很開心。