=~(p1)
public
Match—If obj is a Regexp, use it as a
pattern to match against str,and
returns the position the match starts, or
nil if there is no match. Otherwise,
invokes obj.=~, passing str as an argument. The default
~ in Object returns false.
"cat o' 9 tails" =~ /\d/
"cat o' 9 tails" =~ 9
Show source
/*
* call-seq:
* str =~ obj => fixnum or nil
*
* Match---If <i>obj</i> is a <code>Regexp</code>, use it as a pattern to match
* against <i>str</i>,and returns the position the match starts, or
* <code>nil</code> if there is no match. Otherwise, invokes
* <i>obj.=~</i>, passing <i>str</i> as an argument. The default
* <code>=~</code> in <code>Object</code> returns <code>false</code>.
*
* "cat o' 9 tails" =~ /\d/
* "cat o' 9 tails" =~ 9
*/
static VALUE
rb_str_match(x, y)
VALUE x, y;
{
switch (TYPE(y)) {
case T_STRING:
rb_raise(rb_eTypeError, "type mismatch: String given");
case T_REGEXP:
return rb_reg_match(y, x);
default:
return rb_funcall(y, rb_intern("=~"), 1, x);
}
}