Skip to content

Commit

Permalink
Add Regexp#match?. #4293.
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Nov 17, 2016
1 parent f2f2ca2 commit 689a7ea
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions core/src/main/java/org/jruby/RubyRegexp.java
Expand Up @@ -1116,6 +1116,18 @@ public IRubyObject match_m19(ThreadContext context, IRubyObject str, IRubyObject
return match19Common(context, str, RubyNumeric.num2int(pos), true, block);
}

@JRubyMethod(name = "match?")
public IRubyObject match_p(ThreadContext context, IRubyObject str) {
IRubyObject[] dummy = new IRubyObject[1];
return context.runtime.newBoolean(matchPos(context, str, dummy, dummy, 0) >= 0);
}

@JRubyMethod(name = "match?")
public IRubyObject match_p(ThreadContext context, IRubyObject str, IRubyObject pos) {
IRubyObject[] dummy = new IRubyObject[1];
return context.runtime.newBoolean(matchPos(context, str, dummy, dummy, RubyNumeric.num2int(pos)) > 0);
}

private IRubyObject match19Common(ThreadContext context, IRubyObject str, int pos, boolean setBackref, Block block) {
IRubyObject[] holder = setBackref ? null : new IRubyObject[] { context.nil };
if (matchPos(context, str, null, holder, pos) < 0) {
Expand Down

0 comments on commit 689a7ea

Please sign in to comment.