0

我在一个适用于其他所有人的 repo 中检查了一个新的提交。我运行一个 rake 任务,它调用此代码并引发undefined错误,即使Gem.source_index似乎已定义。

module Gem
  puts "in module Gem"
  def self.source_index=(index)
    puts "defining the source index"
    @@source_index = index
  end
end

module Rails
  class GemDependency < Gem::Dependency
    attr_accessor :lib, :source, :dep

    def self.add_frozen_gem_path
      puts "Oh hi there"
      puts "the source index is " + Gem.source_index // ERROR HERE
    end

输出是

in module Gem
Oh hi there
rake aborted!
undefined method `source_index' for Gem:Module

怎么了?

4

1 回答 1

1

Gem.source_index在 Ruby 1.9 中已弃用并在 Ruby 2.0* 中删除。我怀疑您现在使用的是 Ruby 2.0,这会给您带来确切的错误。

请注意,您确实为它定义了一个 setter,但没有定义一个 getter。

(* 从技术上讲,它可能与特定版本的 Rubygems 而不是 Ruby 相关联。1.9.3 安装和升级的 ruby​​gems 安装将等同于同样的事情。)

于 2013-04-30T00:31:37.360 回答