Gbe*_*her 5 ruby activerecord ruby-on-rails
如何删除警告warning: delegator does not forward private method #to_ary?
以下是使用给定技术重现问题的代码片段:
class Foo < ActiveRecord::Base
def name
"foobar"
end
end
class FooDelegator < SimpleDelegator
def name
"name"
end
end
pry(main)> [FooDelegator.new(Foo.new)].flatten
(pry):12: warning: delegator does not forward private method #to_ary
=> [#<Foo:0x00007f3fa3b1ebf0 id: nil, created_at: nil, updated_at: nil>]
Run Code Online (Sandbox Code Playgroud)
编辑:这个问题也发布在 Github 上,因为我认为它实际上属于 ActiveRecord (rails)。
链接: https: //github.com/rails/rails/issues/48059
public :to_ary在ActiveRecord类中使用将私有方法转换为公共方法:
class Foo < ActiveRecord::Base
def name
"foobar"
end
public :to_ary
end
class FooDelegator < SimpleDelegator
def name
"name"
end
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
243 次 |
| 最近记录: |