Ruby on Rails中,避免在`definition-context.rb`第36行取消`initialize`定义,以防误转为长尾。
- 内容介绍
- 文章标签
- 相关推荐
本文共计368个文字,预计阅读时间需要2分钟。
我在3.1版本的CentOS上安装了一个新的宝石针。它安装正确,但当使用`rails server -debugger`启动我的Rails时,我收到了以下警告:.rvm/gems/ruby-1.9.2-p290/gems/needle-1.3.0/lib/needle/definition-context.rb:36:
我在导轨3.1中安装了一个新的宝石针.它正确安装,但是当我使用命令rails server –debugger启动我的rails时
我收到以下警告:
.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
我怎么能摆脱它?
问题在于针宝石本身.它这样做: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>]
什么时候不应该删除提供的数组中的那些方法.
这向我表明该库尚未针对Ruby 1.9进行更新(或至少已经过测试).我建议找到这个库的代码,分叉它然后应用一个补丁,使用map(&:to_sym)之类的东西将数组转换为符号来解决这个问题.
但请注意:可能存在其他情况,即1.8和1.9之间存在这些差异.
本文共计368个文字,预计阅读时间需要2分钟。
我在3.1版本的CentOS上安装了一个新的宝石针。它安装正确,但当使用`rails server -debugger`启动我的Rails时,我收到了以下警告:.rvm/gems/ruby-1.9.2-p290/gems/needle-1.3.0/lib/needle/definition-context.rb:36:
我在导轨3.1中安装了一个新的宝石针.它正确安装,但是当我使用命令rails server –debugger启动我的rails时
我收到以下警告:
.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
我怎么能摆脱它?
问题在于针宝石本身.它这样做: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>]
什么时候不应该删除提供的数组中的那些方法.
这向我表明该库尚未针对Ruby 1.9进行更新(或至少已经过测试).我建议找到这个库的代码,分叉它然后应用一个补丁,使用map(&:to_sym)之类的东西将数组转换为符号来解决这个问题.
但请注意:可能存在其他情况,即1.8和1.9之间存在这些差异.

