Skip to content

Commit d562b7f

Browse files
committed
Allow rb_hash_lookup2 to returna a default value of Qundef
1 parent 48e5f1e commit d562b7f

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/main/c/cext/ruby.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1655,7 +1655,11 @@ VALUE rb_hash_lookup(VALUE hash, VALUE key) {
16551655
}
16561656

16571657
VALUE rb_hash_lookup2(VALUE hash, VALUE key, VALUE default_value) {
1658-
return RUBY_INVOKE(hash, "fetch", key, default_value);
1658+
VALUE result = RUBY_INVOKE(hash, "_get_or_undefined", key);
1659+
if (result == Qundef) {
1660+
result = default_value;
1661+
}
1662+
return result;
16591663
}
16601664

16611665
VALUE rb_hash_set_ifnone(VALUE hash, VALUE if_none) {

0 commit comments

Comments
 (0)