Range Oddity

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Range Oddity

keithrbennett
All -

I'm having a strange issue and am wondering if you might know anything about it.

I'm troubleshooting a piece of code that has something like this in it:

0..16.times { ... }

I believe the 0.. is extraneous and the code should behave as:

0..(16.times { ... } )

And the return value of the expression is not used so I think it should be equivalent to simply:

16.times { ... }

However, sometimes when this code is run the block appears to execute 0 times instead of 16.  This happens only when the code is run in JRuby (jruby-1.7.16 and jruby-1.6.8 on both OS X and Linux); not on MRI Ruby 1.9.3 and 2.1.4.

Unfortunately I'm unable to provide a minimal test case.

Does this ring a bell for anyone?  Any clue as to what might be happening?

Thanks,
Keith

Reply | Threaded
Open this post in threaded view
|

Re: Range Oddity

Christian MICHON

The 3rd snippet is the only valid style.

Obviously a refactoring uncompleted or untested.

On Nov 9, 2014 7:18 AM, "Keith Bennett" <[hidden email]> wrote:
All -

I'm having a strange issue and am wondering if you might know anything about it.

I'm troubleshooting a piece of code that has something like this in it:

0..16.times { ... }

I believe the 0.. is extraneous and the code should behave as:

0..(16.times { ... } )

And the return value of the expression is not used so I think it should be equivalent to simply:

16.times { ... }

However, sometimes when this code is run the block appears to execute 0 times instead of 16.  This happens only when the code is run in JRuby (jruby-1.7.16 and jruby-1.6.8 on both OS X and Linux); not on MRI Ruby 1.9.3 and 2.1.4.

Unfortunately I'm unable to provide a minimal test case.

Does this ring a bell for anyone?  Any clue as to what might be happening?

Thanks,
Keith