Add new function `mrb_ensure_hash_type()`; ref
Unlike `mrb_check_hash_type()` that returns `nil` if the argument is
not a `Hash`, `mrb_ensure_hash_type()` raises a `TypeError` exception.
MODIFY
include/mruby/hash.h
include/mruby/hash.h
@@ -25,6 +25,7 @@ struct RHash {
#define mrb_hash_value(p) mrb_obj_value((void*)(p))
MRB_API mrb_value mrb_hash_new_capa(mrb_state*, mrb_int);
+MRB_API mrb_value mrb_ensure_hash_type(mrb_state *mrb, mrb_value hash);
MRB_API mrb_value mrb_check_hash_type(mrb_state *mrb, mrb_value hash);
/*

MODIFY
src/hash.c
src/hash.c
@@ -320,6 +320,12 @@ mrb_hash_set(mrb_state *mrb, mrb_value hash, mrb_value key, mrb_value val)
return;
}
+MRB_API mrb_value
+mrb_ensure_hash_type(mrb_state *mrb, mrb_value hash)
+{
+ return mrb_convert_type(mrb, hash, MRB_TT_HASH, "Hash", "to_hash");
+}
+
MRB_API mrb_value
mrb_check_hash_type(mrb_state *mrb, mrb_value hash)
{
@@ -959,7 +965,7 @@ mrb_hash_merge(mrb_state *mrb, mrb_value hash1, mrb_value hash2)
khiter_t k;
mrb_hash_modify(mrb, hash1);
- hash2 = mrb_check_hash_type(mrb, hash2);
+ hash2 = mrb_ensure_hash_type(mrb, hash2);
h1 = RHASH_TBL(hash1);
h2 = RHASH_TBL(hash2);

Add new function `mrb_ensure_hash_type()`; ref #4097

Unlike `mrb_check_hash_type()` that returns `nil` if the argument is
not a `Hash`, `mrb_ensure_hash_type()` raises a `TypeError` exception.