Exemple #1
0
 private IRubyObject stepCommon19(ThreadContext context, IRubyObject step, Block block) {
   Ruby runtime = context.getRuntime();
   if (begin instanceof RubyFixnum && end instanceof RubyFixnum && step instanceof RubyFixnum) {
     fixnumStep(context, runtime, ((RubyFixnum) step).getLongValue(), block);
   } else if (begin instanceof RubyFloat
       || end instanceof RubyFloat
       || step instanceof RubyFloat) {
     RubyNumeric.floatStep19(context, runtime, begin, end, step, isExclusive, block);
   } else if (begin instanceof RubyNumeric
       || !checkIntegerType(runtime, begin, "to_int").isNil()
       || !checkIntegerType(runtime, end, "to_int").isNil()) {
     numericStep19(context, runtime, step, block);
   } else {
     IRubyObject tmp = begin.checkStringType();
     if (!tmp.isNil()) {
       StepBlockCallBack callback = new StepBlockCallBack(block, RubyFixnum.one(runtime), step);
       Block blockCallback =
           CallBlock.newCallClosure(
               this, runtime.getRange(), Arity.singleArgument(), callback, context);
       ((RubyString) tmp).uptoCommon19(context, end, isExclusive, blockCallback);
     } else {
       if (!begin.respondsTo("succ"))
         throw runtime.newTypeError("can't iterate from " + begin.getMetaClass().getName());
       // range_each_func(range, step_i, b, e, args);
       rangeEach(context, new StepBlockCallBack(block, RubyFixnum.one(runtime), step));
     }
   }
   return this;
 }
Exemple #2
0
 private IRubyObject stepCommon(
     ThreadContext context, IRubyObject to, IRubyObject step, Block block) {
   Ruby runtime = context.runtime;
   if (this instanceof RubyFixnum && to instanceof RubyFixnum && step instanceof RubyFixnum) {
     fixnumStep(
         context,
         runtime,
         ((RubyFixnum) this).getLongValue(),
         ((RubyFixnum) to).getLongValue(),
         ((RubyFixnum) step).getLongValue(),
         block);
   } else if (this instanceof RubyFloat || to instanceof RubyFloat || step instanceof RubyFloat) {
     floatStep19(context, runtime, this, to, step, false, block);
   } else {
     duckStep(context, runtime, this, to, step, block);
   }
   return this;
 }