Rubocop: has_key? deprecated?

Created on 15 Jun 2016  路  3Comments  路  Source: rubocop-hq/rubocop

The Style/DeprecatedHashMethods cop says, that has_key? is deprecated in favor of key?, citing a four year old message from @matz: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/43765

The ruby 2.3.1 documentation does not mention the deprecation and has_key? is mentioned all over the place, even as example for key?: http://ruby-doc.org/core-2.3.1/Hash.html#method-i-key-3F

So is this really deprecated?

Most helpful comment

Although I prefer key? and recommend to use it over has_key?, it is not going to be removed, even in Ruby3.

All 3 comments

Looking at the doc and source, seems like key? is just an alias of has_key?. Similarly value? is an alias of has_value?.

If Matz said it is deprecated, we should assume it won't be in Ruby 3. The only thing missing is a note in the Ruby documentation.

Although I prefer key? and recommend to use it over has_key?, it is not going to be removed, even in Ruby3.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mikegee picture mikegee  路  3Comments

herwinw picture herwinw  路  3Comments

joromir picture joromir  路  3Comments

ecbrodie picture ecbrodie  路  3Comments

mlammers picture mlammers  路  3Comments