[Ironruby-core] Range patch

Peter Bacon Darwin bacondarwin at googlemail.com
Fri Jan 25 09:53:12 EST 2008


Sorry, I introduced a small bug since I didn't check all the other specs
were still working (tut tut).  The String#upto spec picked up a quirk of MRI
that I broke in rbx:

 

  # This is weird but MRI behaves like that

  it "upto calls block with self even if self is less than stop but stop
length is less than self length" do

    a = []

    "25".upto("5") { |s| a << s }

    a.should == ["25"]

  end

 

  it "upto doesn't call block if stop is less than self and stop length is
less than self length" do

    a = []

    "25".upto("1") { |s| a << s }

    a.should == []

  end

 

This behaviour is also true for Range#each and Range#step too.  The fix is
as follows.  If it is a problem I can resubmit the whole patch with this fix
incorporated.

 

Inside the RangeOps.cs file, get rid of the CompareString method and change
StepString to:

 

        private static Range StepString(CodeContext/*!*/ context, Range/*!*/
self, BlockParam block, MutableString begin, MutableString end, int step) {

            CheckStep(step);

            MutableString item = begin;

            int comp;

            while((comp = Protocols.Compare(context, item, end)) < 0) {

                if (block.BlockJumped(_BlockSite.Invoke(context, block,
item))) {

                    return self;

                }

                for (int i = 0; i < step; ++i) {

                    item = (MutableString)RubySites.Successor(context,
item);

                }

                if (item.Length > end.Length) {

                    return self;

                }

            }

            if (comp == 0 && !self.ExcludeEnd) {

                _BlockSite.Invoke(context, block, item);

            }

            return self;

        }

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/ironruby-core/attachments/20080125/48ff02f9/attachment.html 


More information about the Ironruby-core mailing list