Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
There seems to be a difference in how JRuby and Ruby handle insertion of elements into an array that is being iterated over.
The version of JRuby doesn't seem to matter. Therefore I suspect a fairly old incompatibility
Versions:
rules = [1, 2, 3, 4, 5] rules.delete_if.with_index do |rule, index| p rule rules.insert(index + 1, 2) if rule == 1 true end
Execute the code above with both JRuby and Ruby. E.g. ruby file_name.rb
Expected Behavior Ruby
1 2 2 3 4 5
Actual Behavior JRuby
1 2 2 3 4
I guess that JRuby sets the max_index/end of an iteration at the beginning of an iteration and Ruby adapts that end if an insert occurs.
I do not want to impose this behaviour on JRuby if it is not how it's intended to be. But I expected it to behave like Ruby.