Skip to content

Commit

Permalink
added Symbol#[]
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/branches/icu@3743 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information
lrz committed Mar 12, 2010
1 parent a7c5ade commit d13c044
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions encoding.h
Expand Up @@ -291,6 +291,7 @@ str_set_valid_encoding(rb_str_t *self, bool status)

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.
Expand Down
2 changes: 1 addition & 1 deletion string.c
Expand Up @@ -1640,7 +1640,7 @@ rb_str_subpat(VALUE str, VALUE re, int nth)
return Qnil;
}

static VALUE
VALUE
rstr_aref(VALUE str, SEL sel, int argc, VALUE *argv)
{
if (argc == 2) {
Expand Down
15 changes: 15 additions & 0 deletions symbol.c
Expand Up @@ -607,6 +607,20 @@ rsym_empty(VALUE sym, SEL sel)
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)
{
Expand Down Expand Up @@ -643,6 +657,7 @@ Init_Symbol(void)
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",
Expand Down

0 comments on commit d13c044

Please sign in to comment.