Project

General

Profile

Actions

Bug #16486

closed

Hash.ruby2_keywords?(hash) and Hash.ruby2_keywords!(hash)

Added by mame (Yusuke Endoh) almost 5 years ago. Updated over 4 years ago.

Status:
Closed
Target version:
-
[ruby-core:96687]

Description

Hash's ruby2_keywords flag is designed to be as implicit as possible, but unfortunately, sometimes we need to handle the flag explicitly. In ActiveJob, the whole arguments are serialized and deserialized, and the process removes the flag; in this case, we need to check and save the flag when serializing, and restore the flag when deserializing.

https://github.com/rails/rails/pull/38105#discussion_r361863767

It is theoretically possible by a very hacky code, but it would be good to provide them officially.

https://github.com/ruby/ruby/pull/2818

  • Hash.ruby2_keywords?(hash) checks if hash is flagged or not.
  • Hash.ruby2_keywords!(hash) flags a given hash.

The reason why I don't add them as instance methods (Hash#ruby2_keywords?) is that they are never for casual use. The ruby2_keywords flag will be removed after enough migration time. Casual use of them will make it difficult to remove, so I'd like to keep them for non-casual use.

(I thought RubyVM.ruby2_keywords?(hash) is good but @Eregon (Benoit Daloze) will be against it :-)

@jeremyevans0 (Jeremy Evans) Could you tell me your opinion?

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0