Skip to content

Commit

Permalink
implement Symbol#match
Browse files Browse the repository at this point in the history
  • Loading branch information
Watson1978 committed Jun 23, 2012
1 parent 2cc16aa commit 64299cd
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/ruby/intern.h
Expand Up @@ -561,6 +561,7 @@ void rb_str_setter(VALUE, ID, VALUE*);
VALUE rb_str_intern(VALUE);
VALUE rb_sym_to_s(VALUE);
VALUE rb_str_length(VALUE);
VALUE rb_str_match(VALUE, VALUE);

// Return a string object appropriate for bstr_ calls. This does nothing for
// data/binary RubyStrings.
Expand Down
2 changes: 0 additions & 2 deletions spec/frozen/tags/macruby/core/symbol/match_tags.txt

This file was deleted.

6 changes: 6 additions & 0 deletions string.c
Expand Up @@ -3168,6 +3168,12 @@ rstr_match(VALUE self, SEL sel, VALUE other)
}
}

VALUE
rb_str_match(VALUE self, VALUE other)
{
return rstr_match(self, 0, other);
}

/*
* call-seq:
* str.scan(pattern) => array
Expand Down
15 changes: 15 additions & 0 deletions symbol.c
Expand Up @@ -676,6 +676,19 @@ rsym_aref(VALUE sym, SEL sel, int argc, VALUE *argv)
return rstr_aref(RSYM(sym)->str, sel, argc, argv);
}

/*
* call-seq:
* sym =~ obj -> fixnum or nil
*
* Returns <code>sym.to_s =~ obj</code>.
*/

static VALUE
rsym_match(VALUE sym, SEL sel, VALUE other)
{
return rb_str_match(rb_sym_to_s(sym), other);
}

/*
* call-seq:
* sym.upcase => symbol
Expand Down Expand Up @@ -799,6 +812,8 @@ Init_Symbol(void)
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);
rb_objc_define_method(rb_cSymbol, "=~", rsym_match, 1);
rb_objc_define_method(rb_cSymbol, "match", rsym_match, 1);
rb_objc_define_method(rb_cSymbol, "upcase", rsym_upcase, 0);
rb_objc_define_method(rb_cSymbol, "downcase", rsym_downcase, 0);
rb_objc_define_method(rb_cSymbol, "swapcase", rsym_swapcase, 0);
Expand Down

0 comments on commit 64299cd

Please sign in to comment.