Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 
like image 276
Autodidact Avatar asked Jan 17 '11 09:01

Autodidact


2 Answers

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.

like image 117
sepp2k Avatar answered Sep 30 '22 15:09

sepp2k


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.

like image 32
0x4a6f4672 Avatar answered Sep 30 '22 16:09

0x4a6f4672