Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Range#size missing from JRuby 1.7.8 in 2.0 mode #1252
Range#size appears to be missing from the latest JRuby in Ruby 2.0.0 mode. Range#size was added to Ruby in 2.0.0. The other new Range methods added, like #bsearch, appear to be there -- only #range is missing.
Enumerator#size appears to be defective and may be related:
For comparison, here's the MRI 2.0 behavior:
I'd be happy to send in a PR for this if you could point me in the direction of where this should be implemented. It looks like the RubyRange.java and RubyEnumerator.java classes are probably the most obvious places, but I wanted to ask before just sending in a PR for that (+tests).
Hey @tedpennings, hopefully I'm not chiming in too late, but there's been a couple of recent changes that should help you fix this up:
Then you'll be able to delete
Hope that helps! Let me know if you have any questions...
How do the above two commits look? Is there anything that should be done in there to ensure that the @JRubyMethod is only available in 2.0+ mode? (1.9 doesn't have a Range#size method)
I'll take another look at the Range#step and Range#each enumerator size problem tomorrow. I think that's a bit bigger. It might be worth a separate issue. I can create it if that would help.
Looking good @tedpennings! A few notes:
As for 2.0 vs. 1.9: the next major version of JRuby (the version being worked on in master) will only support a single Ruby version, so what you've got here is correct.
Finally, good call on
Hope that all makes sense! Thanks again, and feel free to let me know if you have more questions.
Ok @dmarcotte - I'll rebase when I get home.
You're right re RubyNumeric instead of RubyInteger. I was thinking of the (quirky) MRI 2.0 behavior where it will return a size for a range of floats, and an Enumerable with size for each/step, but it won't return an array for them.
Last night another test case came to mind that I think we need to consider. RubyNumeric/intervalStepSize doesn't handle RubyBignum. For a range size, that's actually a significant limitation, so RubyNumeric.intervalStepSize might need refactoring.
Here's the error you get with my present PR from Bignums:
referenced this pull request
Dec 3, 2013
Hrm... looks like you were working on master in your fork, so I think when you rebased it and force-pushed, the commits you pulled in are now in a strict sense "different" from the ones already in jruby/master.
You should be able to avoid this by always working on a branch in your fork, and keeping its master up to date from jruby/master with
Note that since the rebase monkeyed with your master's history, to get back to a good state, the easiest thing may be to re-fork and apply your changes in a branch there.
Hope that solves it for you... as always, more questions are welcome.
Thanks, doing that now. I'll create a new PR once it's done.
I think I'm going to add some rspec tests for different strange range conditions too, just so we have our bases covered re integer overflows and casts, e.g., (Fixnum..Bignum).size #=> Fixnum; (Fixnum..Bignum).size #=> Bignum; (Bignum..Bignum).size #=> Fixnum, etc
The specs sound great too, but I'd say they should be sent to RubySpec rather than be added here, so you should be good to go with the PR as-is.
Let me know if you need anything else!
(Oh, and let me know if it'll be a while before you can send for whatever reason. No worries if that's the case! It's just that I'm putting off sending a change that would conflict with yours to avoid causing you churn, but I don't want to sit on it too long.)