2012-01-17 83 views
3

我在rails 3.1中安装了一个新的gem针。needle/definition-context.rb:36:warning:undefining`initialize'may cause serious problems

它正确安装,但是当我使用命令rails server --debugger

我碰到下面的警告开始我的轨道:

.rvm/gems/ruby-1.9.2-p290/gems/needle-1.3.0/lib/needle/definition-context.rb:36: warning: undefining `initialize' may cause serious problems 
.rvm/gems/ruby-1.9.2-p290/gems/needle-1.3.0/lib/needle/definition-context.rb:36: warning: undefining 'object_id' may cause serious problems 
.rvm/gems/ruby-1.9.2-p290/gems/needle-1.3.0/lib/needle/definition-context.rb:36: warning: undefining '__send__' may cause serious problems 

我怎样才能摆脱它?

回答

7

问题出在针状宝石本身。它这样做是:

public_instance_methods - 
[ "instance_eval", "object_id", "__id__", "__send__", "initialize", 
    "remove_const", "method_missing", "method", "class", "inspect", "to_s", 
    "instance_variables", "block_given?" ] 

但是在Ruby 1.9的public_instance_methods方法返回的Symbol品种,不String对象。所以会发生什么有效的是这样的:

[:__send__, <and other methods>] - ["__send__", <and other methods>] 
=> [:__send__, <and other methods>] 

当它应该是不删除所提供的Array那些方法。

这表明该库尚未更新(或至少测试过)Ruby 1.9。我会建议找到这个库的代码,分叉它,然后应用一个补丁,使用类似map(&:to_sym)这样的东西来将数组转换为符号来解决这个问题。

但请注意:可能存在1.8和1.9之间存在这些差异的其他情况。

+0

这支队伍力量强大。 – 2012-01-17 07:30:35

+0

谢谢Rayn ......这真的有道理! – 2012-01-18 05:59:08