The Elements of Style in Ruby #9: Hash#has_key? and Hash#has_value? are deprecated

One can often find similar code in the wild:

some_hash.has_key?(some_key)

has_something? predicates are not idiomatic in Ruby and Hash#has_key? and Hash#has_value? are nothing, but remnants of the early days of Ruby. In fact, according to Matz, they are deprecated in favor of Hash#key? and Hash#value?.

The above snippet should look like:

some_hash.key?(some_key)

As usual - you can use RuboCop to identify and fix such shortfalls of your code.

Comments