DEPRECATION WARNING: Object#returning has been deprecated in favor of Object#tap
Asked Answered
Z

2

10

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 
Zincography answered 17/1, 2011 at 9:18 Comment(0)
L
14

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.

Ligate answered 17/1, 2011 at 9:32 Comment(0)
Y
3

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.

Ysabel answered 25/1, 2013 at 14:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.