I've seen a change in behaviour of Hash.ruby2_keywords_hash? in JRuby v10 manifested as some test failures in this Mocha CI build.
I've managed to narrow the problem down with the following tests where the last test fails in JRuby but passes in CRuby (see below). I don't know whether it's significant that the method is a constructor and I'm only guessing that it's related to whether it's the last argument or not.
# ruby2_keywords_hash_test.rb
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'minitest'
gem 'ruby2_keywords'
end
require 'minitest/autorun'
require 'ruby2_keywords'
class Ruby2KeywordsHashTest < Minitest::Test
def test_hash_is_ruby2_keywords_hash
hash = Hash.ruby2_keywords_hash({ key_1: 1, key_2: 2 })
assert ::Hash.ruby2_keywords_hash?(hash)
end
def test_hash_passed_in_to_object_constructor_is_ruby2_keywords_hash
klass = Class.new do
attr_reader :value
def initialize(value)
@value = value
end
end
hash = Hash.ruby2_keywords_hash({ key_1: 1, key_2: 2 })
object = klass.new(hash)
assert ::Hash.ruby2_keywords_hash?(object.value)
end
def test_hash_passed_in_to_object_constructor_as_non_last_argument_is_ruby2_keywords_hash
klass = Class.new do
attr_reader :value1
def initialize(value1, value2 = nil)
@value1 = value1
end
end
hash = Hash.ruby2_keywords_hash({ key_1: 1, key_2: 2 })
object = klass.new(hash)
assert ::Hash.ruby2_keywords_hash?(object.value1)
end
end
ruby -v
jruby 10.0.0.0 (3.4.2) 2025-04-13 6ed59bc847 OpenJDK 64-Bit Server VM 23.0.2 on 23.0.2 +indy +jit [arm64-darwin]
uname -a
Darwin belgica 24.4.0 Darwin Kernel Version 24.4.0: Fri Apr 11 18:33:47 PDT 2025; root:xnu-11417.101.15~117/RELEASE_ARM64_T6000 arm64
ruby ruby2_keywords_hash_test.rb
Run options: --seed 29092
# Running:
.F.
Finished in 0.011017s, 272.3095 runs/s, 272.3095 assertions/s.
1) Failure:
Ruby2KeywordsTest#test_hash_passed_in_to_object_constructor_as_non_last_argument_is_ruby2_keywords_hash [ruby2_keywords_hash_test.rb:41]:
Expected false to be truthy.
3 runs, 3 assertions, 1 failures, 0 errors, 0 skips
These tests all pass under CRuby v3.4 on the same version of MacOS:
ruby -v
ruby 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [arm64-darwin24]
uname -a
Darwin belgica 24.4.0 Darwin Kernel Version 24.4.0: Fri Apr 11 18:33:47 PDT 2025; root:xnu-11417.101.15~117/RELEASE_ARM64_T6000 arm64
ruby ruby2_keywords_hash_test.rb
Run options: --seed 65142
# Running:
...
Finished in 0.000316s, 9493.6703 runs/s, 9493.6703 assertions/s.
3 runs, 3 assertions, 0 failures, 0 errors, 0 skips
I've seen a change in behaviour of
Hash.ruby2_keywords_hash?in JRuby v10 manifested as some test failures in this Mocha CI build.I've managed to narrow the problem down with the following tests where the last test fails in JRuby but passes in CRuby (see below). I don't know whether it's significant that the method is a constructor and I'm only guessing that it's related to whether it's the last argument or not.
These tests all pass under CRuby v3.4 on the same version of MacOS: