def bar(key:)
key
end
ruby2_keywords def foo(*args)
args = Marshal.load(Marshal.dump(args))
bar(*args)
end
foo(key: 42) #=> 42
Honestly, I'm not fully convinced if this is really needed. It would be helpful for applications and libraries that serializes the whole arguments by using Marshal, e.g., drb. (Currently, drb does not support keyword separation.) But I'm unsure how many applications does so; ActiveJob and Sidekiq use their own dedicated serialization mechanism based on JSON. This patch does not help them, and they should use #16486 to support ruby2_keywords flag. I'd like to hear opinions.
Makes sense to me that Marshal knows how to preserve that flag.
(Sidekiq used Marshal in previous versions, but switched to a manual copy for efficiency)
marshal.c: Support dump and load of a Hash with the ruby2_keywords flag
It is useful for a program that dumps and load arguments (like drb).
In future, they should deal with both positional arguments and keyword
ones explicitly, but until ruby2_keywords is deprecated, it is good to
support the flag in marshal.
The implementation is similar to String's encoding; it is dumped as a
hidden instance variable.