弃用警告:Object#returning 已被弃用,取而代之的是 Object#tap

发布于 2024-10-12 12:15:57 字数 535 浏览 1 评论 0原文

如何更改以下方法以使用 tap 来停止警告,例如

DEPRECATION WARNING: Object#returning 已被弃用,转而使用 Object#tap。 (从 /Users/millisami/apps/pandahr/config/initializers/fix_active_model_full_message.rb:17 处的 full_messages 调用) :

ActiveModel::Errors.class_eval do
  # Remove complicated logic
  def full_messages
    returning full_messages = [] do
      self.each_key do |attr|
        self[attr].each do |msg|
          full_messages << msg if msg 
        end 
      end 
    end 
  end 
end 

How to change the following method to use tap to stop the warnings like

DEPRECATION WARNING: Object#returning has been deprecated in favor of Object#tap. (called from full_messages at /Users/millisami/apps/pandahr/config/initializers/fix_active_model_full_message.rb:17)
:

ActiveModel::Errors.class_eval do
  # Remove complicated logic
  def full_messages
    returning full_messages = [] do
      self.each_key do |attr|
        self[attr].each do |msg|
          full_messages << msg if msg 
        end 
      end 
    end 
  end 
end 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

分開簡單 2024-10-19 12:15:57

一般来说,您可以将 returning 行替换为对 tap 的调用:

[].tap do |full_messages|

但是您的方法看起来与 values.compact 等效,因此您可以只需用它替换您的代码即可。

In general you can replace the returning line with this call to tap:

[].tap do |full_messages|

However your method looks like it's equivalent to values.compact, so you can just replace your code with that.

╭⌒浅淡时光〆 2024-10-19 12:15:57

This warning message can occur if you upgrade old Rails 2 applications. Since the Rails Version 2.3.9 the Kernel#returning function has been replaced with Object#tap which is native to Ruby 1.8.7. Unfortunately this error often is caused by older plugins and gems. For me it helped to update the haml version from 2.0.x to 3.0.21, and the will_paginate version from 2.2.x to 2.3.15.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文