=~(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
static VALUE
rb_str_match(VALUE x, VALUE 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);
}
}