From: fatkodima123@... Date: 2020-08-27T10:29:15+00:00 Subject: [ruby-core:99730] [Ruby master Feature#15573] Permit zero step in Numeric#step and Range#step Issue #15573 has been updated by fatkodima (Dima Fatko). Mathematically, it is allowed that step can be 0, but from practical stand point - this is an infinite loop waiting to be happen. The original issue was about inconsistencies, so I decided to allow `0` for consistency (mainly because there is an `ArithmeticSequence` which allows that) and deprecate raising an exception. Or we can rewrite the `ArithmeticSequence` to raise and deprecate accepting 0 for all methods. PR: https://github.com/ruby/ruby/pull/3462 ---------------------------------------- Feature #15573: Permit zero step in Numeric#step and Range#step https://bugs.ruby-lang.org/issues/15573#change-87223 * Author: mrkn (Kenta Murata) * Status: Open * Priority: Normal * Assignee: mrkn (Kenta Murata) ---------------------------------------- Numeric#step disallows zero in the 2nd argument, but it allows zero passed as the value of `by:` keyword argument. I confirmed that this inconsistency exists since 2.3. I want to allow zero in the 2nd argument, too. ``` >> 1.step(10, by: 0) { break } => nil >> 1.step(10, 0) { break } Traceback (most recent call last): 5: from /Users/mrkn/.rbenv/versions/2.6.0/bin/irb:23:in `
' 4: from /Users/mrkn/.rbenv/versions/2.6.0/bin/irb:23:in `load' 3: from /Users/mrkn/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/irb-1.0.0/exe/irb:11:in `' 2: from (irb):5 1: from (irb):5:in `step' ArgumentError (step can't be 0) ``` Moreover, Range#step disallows zero if a block is given. I want to relax also this restriction. ``` >> (1..10).step(0) { break } Traceback (most recent call last): 6: from /Users/mrkn/.rbenv/versions/2.6.0/bin/irb:23:in `
' 5: from /Users/mrkn/.rbenv/versions/2.6.0/bin/irb:23:in `load' 4: from /Users/mrkn/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/irb-1.0.0/exe/irb:11:in `' 3: from (irb):6 2: from (irb):6:in `rescue in irb_binding' 1: from (irb):6:in `step' ArgumentError (step can't be 0) ``` -- https://bugs.ruby-lang.org/ Unsubscribe: