Skip to content

Commit

Permalink
Add Regexp#match?. #4293.
Browse files Browse the repository at this point in the history
headius committed Nov 17, 2016

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
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
Original file line number Diff line number Diff line change
@@ -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) {

0 comments on commit 689a7ea

Please sign in to comment.