Support string key in Struct#[]=.

This commit is contained in:
take_cheeze
2014-05-28 23:14:28 +09:00
parent 0f432e9028
commit 7bc4d08f71
2 changed files with 10 additions and 0 deletions
+8
View File
@@ -660,6 +660,14 @@ mrb_struct_aset(mrb_state *mrb, mrb_value s)
mrb_get_args(mrb, "oo", &idx, &val);
if (mrb_string_p(idx)) {
mrb_value sym = mrb_check_intern_str(mrb, idx);
if (mrb_nil_p(sym)) {
mrb_raisef(mrb, E_INDEX_ERROR, "no member '%S' in struct", idx);
}
idx = sym;
}
if (mrb_symbol_p(idx)) {
return mrb_struct_aset_sym(mrb, s, mrb_symbol(idx), val);
}
+2
View File
@@ -39,6 +39,8 @@ assert('Struct#[]=', '15.2.18.4.3') do
cc = c.new(1,2)
cc[:m1] = 3
cc[:m1] == 3
cc["m2"] = 3
assert_equal 3, cc["m2"]
end
assert('Struct#each', '15.2.18.4.4') do