Bug #9810

Numeric#step behavior with mixed Float, String arguments inconsistent with documentation

Added by Brian Shirai 10 months ago.

[ruby-core:62430]
Status:Open
Priority:Normal
Assignee:-
ruby -v:ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin13.0] Backport:2.0.0: UNKNOWN, 2.1: UNKNOWN

Description

The Numeric#step documentation states:

"If any of the arguments are floating point numbers, all are converted to floats..."

https://github.com/ruby/ruby/blob/trunk/numeric.c#L1921

Is the following code intended to be described by that documentation?

1.1.step(5.1, "1") {}

Previously (eg 2.0.0) resulted in a TypeError:

$ ruby -v -e 'p 1.1.step(5.1, "1") {}'
ruby 2.0.0p247 (2013-06-27) [x86_64-darwin13.0.1]
-e:1:in step': no implicit conversion to float from string (TypeError)
from -e:1:in
'

In 2.1.1, at least, an ArgumentError is raised:

$ ruby -v -e 'p 1.1.step(5.1, "1") {}'
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin13.0]
-e:1:in >': comparison of String with 0 failed (ArgumentError)
from -e:1:in
step'
from -e:1:in `'

What's the intended behavior?

Also available in: Atom PDF