如何删除警告warning: delegator does not forward private method #to_ary
?
以下是使用给定技术重新创建问题的代码片段:
- Ruby 3.2.1
- Rails www.example. com
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>]
编辑:这个问题也发布在Github上,因为我认为它实际上属于ActiveRecord(rails)。
链接:https://github.com/rails/rails/issues/48059
1条答案
按热度按时间ozxc1zmp1#
在ActiveRecord类中使用
public :to_ary
将private方法转换为public方法: