[Ironruby-core] Range patch

John Lam (DLR) jflam at microsoft.com
Fri Jan 25 10:16:45 EST 2008

Thanks for the catch. Will review and submit ASAP.


From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Peter Bacon Darwin
Sent: Friday, January 25, 2008 6:53 AM
To: ironruby-core at rubyforge.org
Subject: [Ironruby-core] Range patch

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"]

  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 == []

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) {
            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/e4663cb1/attachment-0001.html 

More information about the Ironruby-core mailing list