diff options
| author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-02-04 19:17:33 +0000 |
|---|---|---|
| committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-02-04 19:17:33 +0000 |
| commit | 44133346923781aaa1022d9b881aeb4e58dd5940 (patch) | |
| tree | 3f74f159fcc7abf2e87ff7295e6400651a26a8c4 /string.c | |
| parent | 11703607ac25a15def2197bb91e53b4b0d7cf84d (diff) | |
| download | ruby-44133346923781aaa1022d9b881aeb4e58dd5940.tar.gz ruby-44133346923781aaa1022d9b881aeb4e58dd5940.tar.xz ruby-44133346923781aaa1022d9b881aeb4e58dd5940.zip | |
* parse.y (rb_compose_ivar2): function to create a new ivar2
symbol from a symbol and a class. back-ported from matzruby.
* parse.y (rb_decompose_ivar2): reverse function of
rb_compose_ivar2().
* marshal.c (w_symbol): support class local instance variables.
* marshal.c (r_object0): ditto.
* compile.c (defined_expr): ditto.
* compile.c (iseq_compile_each): ditto.
* insns.def: add two new instructions: getinstancevariable2 and
setinstancevariable2.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@11630 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
| -rw-r--r-- | string.c | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -4690,6 +4690,9 @@ sym_inspect(VALUE sym) VALUE str, klass = Qundef; ID id = SYM2ID(sym); + if (rb_is_instance2_id(id)) { + id = rb_decompose_ivar2(id, &klass); + } sym = rb_id2str(id); str = rb_str_new(0, RSTRING_LEN(sym)+1); RSTRING_PTR(str)[0] = ':'; @@ -4723,6 +4726,9 @@ rb_sym_to_s(VALUE sym) { ID id = SYM2ID(sym); + if (rb_is_instance2_id(id)) { + id = rb_decompose_ivar2(id, 0); + } return str_new3(rb_cString, rb_id2str(id)); } @@ -4868,6 +4874,27 @@ rb_to_id(VALUE name) return id; } +static VALUE +sym_div(VALUE sym, VALUE klass) +{ + ID id = SYM2ID(sym); + + if (!rb_is_instance2_id(id)) { + rb_raise(rb_eArgError, "symbol %s should be local instance variable", + rb_id2name(id)); + } + switch (TYPE(klass)) { + case T_CLASS: + case T_MODULE: + break; + default: + rb_check_type(klass, T_CLASS); + break; + } + id = rb_compose_ivar2(id, klass); + return ID2SYM(id); +} + /* * A <code>String</code> object holds and manipulates an arbitrary sequence of * bytes, typically representing characters. String objects may be created @@ -5008,6 +5035,7 @@ Init_String(void) rb_define_singleton_method(rb_cSymbol, "all_symbols", rb_sym_all_symbols, 0); /* in parse.y */ rb_define_singleton_method(rb_cSymbol, "intern", rb_sym_s_intern, 1); + rb_define_method(rb_cSymbol, "/", sym_div, 1); rb_define_method(rb_cSymbol, "==", sym_equal, 1); rb_define_method(rb_cSymbol, "to_i", sym_to_i, 0); rb_define_method(rb_cSymbol, "inspect", sym_inspect, 0); |
