warning: Using the last argument as keyword parameters is deprecated

Viewed 4164
  json: 1.8.6
  ruby: 2.7.2
  rails: 6.0.3.6

I am frequently getting the following error in my application

 /Users/***/.rvm/gems/ruby-2.7.2/gems/json-1.8.6/lib/json/common.rb:155: warning: Using the last argument as keyword parameters is deprecated

When I searched for this error I got a solution i.e., I need to update my json gem version but here I have many other dependencies on the json-1.8.6 version, So I cannot update the gem. When I update the code in common.rb file explicitly.

 def parse(source, opts = {})
    Parser.new(source, opts).parse
 end
 

I have updated above code as follows

def parse(source, opts = {})
  Parser.new(source, **opts).parse
end

It is working without any errors but I think it is not the correct way to disable the warning.

2 Answers

config/initializers/json.rb

 module JSON
   module_function

     def parse(source, opts = {})
     Parser.new(source, **opts).parse
   end
 end

Try updating the particular gem that gives the warning. Do so manually - check the gem website and update the gemfile, then do bundle update. Worked for me!

Related