Ejemplo n.º 1
0
        public static object Step(RubyContext /*!*/ context, BlockParam block, Range /*!*/ self, object step)
        {
            // We attempt to cast step to Fixnum here even though if we were iterating over Floats, for instance, we use step as is.
            // This prevents cases such as (1.0..2.0).step(0x800000000000000) {|x| x } from working but that is what MRI does.
            int intStep = Protocols.CastToFixnum(context, step);

            if (self.Begin is int && self.End is int)
            {
                // self.begin is Fixnum; directly call item = item + 1 instead of succ
                return(StepFixnum(context, block, self, (int)self.Begin, (int)self.End, intStep));
            }
            else if (self.Begin is MutableString)
            {
                // self.begin is String; use item.succ and item <=> self.end but make sure you check the length of the strings
                return(StepString(context, block, self, (MutableString)self.Begin, (MutableString)self.End, intStep));
            }
            else if (context.IsInstanceOf(self.Begin, context.GetClass(typeof(Numeric))))
            {
                // self.begin is Numeric; invoke item = item + 1 instead of succ and invoke < or <= for compare
                return(StepNumeric(context, block, self, self.Begin, self.End, step));
            }
            else
            {
                // self.begin is not Numeric or String; just invoke item.succ and item <=> self.end
                CheckBegin(context, self.Begin);
                return(StepObject(context, block, self, self.Begin, self.End, intStep));
            }
        }
Ejemplo n.º 2
0
 public static object Step(RubyContext/*!*/ context, BlockParam block, Range/*!*/ self, object step) {
     // We attempt to cast step to Fixnum here even though if we were iterating over Floats, for instance, we use step as is.
     // This prevents cases such as (1.0..2.0).step(0x800000000000000) {|x| x } from working but that is what MRI does.
     int intStep = Protocols.CastToFixnum(context, step);
     if (self.Begin is int && self.End is int) {
         // self.begin is Fixnum; directly call item = item + 1 instead of succ
         return StepFixnum(context, block, self, (int)self.Begin, (int)self.End, intStep);
     } else if ( self.Begin is MutableString ) {
         // self.begin is String; use item.succ and item <=> self.end but make sure you check the length of the strings
         return StepString(context, block, self, (MutableString)self.Begin, (MutableString)self.End, intStep);
     } else if (context.IsInstanceOf(self.Begin, context.GetClass(typeof(Numeric)))) {
         // self.begin is Numeric; invoke item = item + 1 instead of succ and invoke < or <= for compare
         return StepNumeric(context, block, self, self.Begin, self.End, step);
     } else {
         // self.begin is not Numeric or String; just invoke item.succ and item <=> self.end
         CheckBegin(context, self.Begin);
         return StepObject(context, block, self, self.Begin, self.End, intStep);
     }
 }
Ejemplo n.º 3
0
        public static object Step(
            ConversionStorage<MutableString>/*!*/ stringCast, 
            ConversionStorage<int>/*!*/ fixnumCast, 
            RespondToStorage/*!*/ respondToStorage,
            BinaryOpStorage/*!*/ comparisonStorage,
            BinaryOpStorage/*!*/ lessThanStorage,
            BinaryOpStorage/*!*/ lessThanEqualsStorage,
            BinaryOpStorage/*!*/ greaterThanStorage,
            BinaryOpStorage/*!*/ equalsStorage,
            BinaryOpStorage/*!*/ addStorage,
            UnaryOpStorage/*!*/ succStorage,
            RubyContext/*!*/ context, BlockParam block, Range/*!*/ self, [Optional]object step) {

            if (step == Missing.Value) {
                step = ScriptingRuntimeHelpers.Int32ToObject(1);
            }
            
            // We attempt to cast step to Fixnum here even though if we were iterating over Floats, for instance, we use step as is.
            // This prevents cases such as (1.0..2.0).step(0x800000000000000) {|x| x } from working but that is what MRI does.
            if (self.Begin is int && self.End is int) {
                // self.begin is Fixnum; directly call item = item + 1 instead of succ
                int intStep = Protocols.CastToFixnum(fixnumCast, context, step);
                return StepFixnum(context, block, self, (int)self.Begin, (int)self.End, intStep);
            } else if (self.Begin is MutableString ) {
                // self.begin is String; use item.succ and item <=> self.end but make sure you check the length of the strings
                int intStep = Protocols.CastToFixnum(fixnumCast, context, step);
                return StepString(stringCast, comparisonStorage, lessThanStorage, greaterThanStorage, succStorage, context,
                    block, self, (MutableString)self.Begin, (MutableString)self.End, intStep
                );
            } else if (context.IsInstanceOf(self.Begin, context.GetClass(typeof(Numeric)))) {
                // self.begin is Numeric; invoke item = item + 1 instead of succ and invoke < or <= for compare
                return StepNumeric(lessThanStorage, lessThanEqualsStorage, equalsStorage, addStorage, context, 
                    block, self, self.Begin, self.End, step
                );
            } else {
                // self.begin is not Numeric or String; just invoke item.succ and item <=> self.end
                CheckBegin(respondToStorage, context, self.Begin);
                int intStep = Protocols.CastToFixnum(fixnumCast, context, step);
                return StepObject(comparisonStorage, lessThanStorage, greaterThanStorage, equalsStorage, succStorage, context,
                    block, self, self.Begin, self.End, intStep
                );
            }
        }