Issue #15537 has been updated by mrkn (Kenta Murata).

Assignee set to mrkn (Kenta Murata)
Status changed from Open to Assigned

----------------------------------------
Bug #15537: Numeric#step doesn't iterate under some conditions
https://bugs.ruby-lang.org/issues/15537#change-76487

* Author: shuujii (Shuji KOBAYASHI)
* Status: Assigned
* Priority: Normal
* Assignee: mrkn (Kenta Murata)
* Target version: 
* ruby -v: ruby 2.6.0p0 (2018-12-25 revision 66547) [x86_64-linux]
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Numeric#step doesn't iterate under the following conditions:

- receiver and/or `by` are `Float`
- `by` is negative
- `to` is default
- without block

### Example:

Good:

~~~ruby
p 1.step(by: 3).take(2)                                     #=> [1, 4]
p 1.step(by: -3).take(2)                                    #=> [1, -2]
p 1.step(by: 3.0).take(2)                                   #=> [1.0, 4.0]
p 1.0.step(by: 3).take(2)                                   #=> [1.0, 4.0]
a=[]; p 1.step(by: -3.0){|n|break a if (a << n).size == 2}  #=> [1.0, -2.0]
a=[]; p 1.0.step(by: -3){|n|break a if (a << n).size == 2}  #=> [1.0, -2.0]
~~~

Bad:

~~~ruby
p 1.step(by: -3.0).take(2)  #=> []
p 1.0.step(by: -3).take(2)  #=> []
~~~

I have attached a patch.

---Files--------------------------------
fix-numeric-step-for-float.patch (2.07 KB)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>