/** match_end */ @JRubyMethod(name = "end", compat = CompatVersion.RUBY1_8) public IRubyObject end(ThreadContext context, IRubyObject index) { int i = RubyNumeric.num2int(index); Ruby runtime = context.getRuntime(); int e = endCommon(runtime, i); return e < 0 ? runtime.getNil() : RubyFixnum.newFixnum(runtime, e); }
private IRubyObject offsetCommon(ThreadContext context, int i, boolean is_19) { check(); Ruby runtime = context.getRuntime(); if (i < 0 || (regs == null ? 1 : regs.numRegs) <= i) throw runtime.newIndexError("index " + i + " out of matches"); int b, e; if (regs == null) { b = begin; e = end; } else { b = regs.beg[i]; e = regs.end[i]; } if (b < 0) return runtime.newArray(runtime.getNil(), runtime.getNil()); if (is_19 && !str.singleByteOptimizable()) { updateCharOffset(); b = charOffsets.beg[i]; e = charOffsets.end[i]; } return runtime.newArray(RubyFixnum.newFixnum(runtime, b), RubyFixnum.newFixnum(runtime, e)); }
@JRubyMethod(name = "end", compat = CompatVersion.RUBY1_9) public IRubyObject end19(ThreadContext context, IRubyObject index) { int i = backrefNumber(index); Ruby runtime = context.getRuntime(); int e = endCommon(runtime, i); if (e < 0) return runtime.getNil(); if (!str.singleByteOptimizable()) { updateCharOffset(); e = charOffsets.end[i]; } return RubyFixnum.newFixnum(runtime, e); }
@JRubyMethod(name = "priority=", required = 1) public IRubyObject priority_set(IRubyObject priority) { // FIXME: This should probably do some translation from Ruby priority levels to Java priority // levels (until we have green threads) int iPriority = RubyNumeric.fix2int(priority); if (iPriority < Thread.MIN_PRIORITY) { iPriority = Thread.MIN_PRIORITY; } else if (iPriority > Thread.MAX_PRIORITY) { iPriority = Thread.MAX_PRIORITY; } if (threadImpl.isAlive()) { threadImpl.setPriority(iPriority); } return RubyFixnum.newFixnum(getRuntime(), iPriority); }
@JRubyMethod(name = "priority=", required = 1) public IRubyObject priority_set(IRubyObject priority) { int iPriority = RubyNumeric.fix2int(priority); if (iPriority < RUBY_MIN_THREAD_PRIORITY) { iPriority = RUBY_MIN_THREAD_PRIORITY; } else if (iPriority > RUBY_MAX_THREAD_PRIORITY) { iPriority = RUBY_MAX_THREAD_PRIORITY; } if (threadImpl.isAlive()) { int jPriority = rubyPriorityToJavaPriority(iPriority); if (jPriority < Thread.MIN_PRIORITY) { jPriority = Thread.MIN_PRIORITY; } else if (jPriority > Thread.MAX_PRIORITY) { jPriority = Thread.MAX_PRIORITY; } threadImpl.setPriority(jPriority); } return RubyFixnum.newFixnum(getRuntime(), iPriority); }
/** match_size */ @JRubyMethod(name = {"size", "length"}) public IRubyObject size(ThreadContext context) { check(); Ruby runtime = context.getRuntime(); return regs == null ? RubyFixnum.one(runtime) : RubyFixnum.newFixnum(runtime, regs.numRegs); }
@JRubyMethod(name = "priority") public RubyFixnum priority() { return RubyFixnum.newFixnum(getRuntime(), threadImpl.getPriority()); }