Revision: 3743 http://trac.macosforge.org/projects/ruby/changeset/3743 Author: lsansonetti@apple.com Date: 2010-03-11 17:59:24 -0800 (Thu, 11 Mar 2010) Log Message: ----------- added Symbol#[] Modified Paths: -------------- MacRuby/branches/icu/encoding.h MacRuby/branches/icu/string.c MacRuby/branches/icu/symbol.c Modified: MacRuby/branches/icu/encoding.h =================================================================== --- MacRuby/branches/icu/encoding.h 2010-03-12 00:36:56 UTC (rev 3742) +++ MacRuby/branches/icu/encoding.h 2010-03-12 01:59:24 UTC (rev 3743) @@ -291,6 +291,7 @@ VALUE mr_enc_s_is_compatible(VALUE klass, SEL sel, VALUE str1, VALUE str2); VALUE rb_str_intern_fast(VALUE str); +VALUE rstr_aref(VALUE str, SEL sel, int argc, VALUE *argv); // The following functions should always been prefered over anything else, // especially if this "else" is RSTRING_PTR and RSTRING_LEN. Modified: MacRuby/branches/icu/string.c =================================================================== --- MacRuby/branches/icu/string.c 2010-03-12 00:36:56 UTC (rev 3742) +++ MacRuby/branches/icu/string.c 2010-03-12 01:59:24 UTC (rev 3743) @@ -1640,7 +1640,7 @@ return Qnil; } -static VALUE +VALUE rstr_aref(VALUE str, SEL sel, int argc, VALUE *argv) { if (argc == 2) { Modified: MacRuby/branches/icu/symbol.c =================================================================== --- MacRuby/branches/icu/symbol.c 2010-03-12 00:36:56 UTC (rev 3742) +++ MacRuby/branches/icu/symbol.c 2010-03-12 01:59:24 UTC (rev 3743) @@ -607,6 +607,20 @@ return rb_str_chars_len(RSYM(sym)->str) == 0 ? Qtrue : Qfalse; } +/* + * call-seq: + * sym[idx] => char + * sym[b, n] => char + * + * Returns <code>sym.to_s[]</code>. + */ + +static VALUE +rsym_aref(VALUE sym, SEL sel, int argc, VALUE *argv) +{ + return rstr_aref(RSYM(sym)->str, sel, argc, argv); +} + static CFIndex rsym_imp_length(void *rcv, SEL sel) { @@ -643,6 +657,7 @@ rb_objc_define_method(rb_cSymbol, "intern", rsym_to_sym, 0); rb_objc_define_method(rb_cSymbol, "to_sym", rsym_to_sym, 0); rb_objc_define_method(rb_cSymbol, "empty?", rsym_empty, 0); + rb_objc_define_method(rb_cSymbol, "[]", rsym_aref, -1); // Cocoa primitives. rb_objc_install_method2((Class)rb_cSymbol, "length",
participants (1)
-
source_changes@macosforge.org