Skip to content

Commit

Permalink
Minor refactoring after last PR (I like early returns vs nesting) and…
Browse files Browse the repository at this point in the history
… unused

assignment.
enebo committed Feb 1, 2018

Verified

This commit was signed with the committer’s verified signature. The key has expired.
nomadium Miguel Landaeta
1 parent ec40e44 commit b51ad8b
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions core/src/main/java/org/jruby/RubyNumeric.java
Original file line number Diff line number Diff line change
@@ -37,9 +37,7 @@
import org.jruby.anno.JRubyClass;
import org.jruby.anno.JRubyMethod;
import org.jruby.ast.util.ArgsUtil;
import org.jruby.common.RubyWarnings;
import org.jruby.exceptions.RaiseException;
import org.jruby.internal.runtime.methods.DynamicMethod;
import org.jruby.javasupport.JavaUtil;
import org.jruby.runtime.Block;
import org.jruby.runtime.CallSite;
@@ -50,7 +48,6 @@
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.callsite.CachingCallSite;
import org.jruby.util.ByteList;
import org.jruby.util.ConvertBytes;
import org.jruby.util.ConvertDouble;
@@ -480,12 +477,11 @@ protected final RubyArray doCoerce(ThreadContext context, IRubyObject other, boo
}

private static RubyArray coerceResult(final Ruby runtime, final IRubyObject result, final boolean err) {
if (!(result instanceof RubyArray) || ((RubyArray) result).getLength() != 2 ) {
if (err || !result.isNil()) throw runtime.newTypeError("coerce must return [x, y]");
return null;
}
if (result instanceof RubyArray && ((RubyArray) result).getLength() == 2) return (RubyArray) result;

return (RubyArray) result;
if (err || !result.isNil()) throw runtime.newTypeError("coerce must return [x, y]");

return null;
}

/** coerce_rescue
@@ -952,9 +948,8 @@ else if (num instanceof RubyBignum) {
return ((RubyBignum) num).isNegative(context).isTrue();
}
}
IRubyObject r = UNDEF;
r = stepCompareWithZero(context, num);
return !r.isTrue();

return !stepCompareWithZero(context, num).isTrue();
}

private IRubyObject stepCompareWithZero(ThreadContext context, IRubyObject num) {

0 comments on commit b51ad8b

Please sign in to comment.