Skip to content

Instantly share code, notes, and snippets.

@methodmissing
Created August 29, 2009 23:56
Show Gist options
  • Select an option

  • Save methodmissing/177779 to your computer and use it in GitHub Desktop.

Select an option

Save methodmissing/177779 to your computer and use it in GitHub Desktop.
static void
rb_strhash_convert(VALUE *val)
{
int i;
VALUE values;
switch (TYPE(*val)) {
case T_HASH:
*val = rb_hash_strhash(*val);
break;
case T_ARRAY:
values = rb_ary_new2(RARRAY_LEN(*val));
for (i = 0; i < RARRAY_LEN(*val); i++) {
VALUE el = RARRAY_PTR(*val)[i];
rb_ary_push(values, (TYPE(el) == T_HASH) ? rb_hash_strhash(el) : el);
}
*val = values;
break;
}
}
static VALUE
rb_strhash_aset(VALUE hash, VALUE key, VALUE val){
rb_strhash_convert(&val);
rb_hash_aset(hash, key, val);
return val;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment