Created
August 29, 2009 23:56
-
-
Save methodmissing/177779 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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