From: "kyanagi (Kouhei Yanagita) via ruby-core" <ruby-core@...>
Date: 2023-10-14T05:57:26+00:00
Subject: [ruby-core:115052] [Ruby master Misc#18984] Doc for Range#size for Float/Rational does not make sense

Issue #18984 has been updated by kyanagi (Kouhei Yanagita).


I created a PR: https://github.com/ruby/ruby/pull/8663

What should we do about `Range#count`?

```
(..0).count # => Infinity
(nil..nil).count # => Infinity
```

----------------------------------------
Misc #18984: Doc for Range#size for Float/Rational does not make sense
https://bugs.ruby-lang.org/issues/18984#change-104927

* Author: masasakano (Masa Sakano)
* Status: Open
* Priority: Normal
----------------------------------------
When `Range` consists of any Numeric, according to [Official docs for Ruby-3.1.2](https://ruby-doc.org/core-3.1.2/Range.html#method-i-size), `Range#size` should, 

> Returns the count of elements in self if both begin and end values are numeric;

Indeed, when `Range` consists of only `Integer`, this makes sense.
However, when the begin value of `Range` is a `Float` or `Rational`, "*the count of elements*" does not make sense. Such Ranges are not iteratable, suggesting there are no such things as "elements":

```ruby
(0.51..5.quo(2)).each{}  # => TypeError
```

Yet, `Range#size` of such Ranges returns an Integer

```ruby
(0.51..5.quo(2)).size  # => 2
```

It seems both begin and end values of a Range are rounded (`Numeric#round`) to the nearest Integer before `Range#size` is calculated.

If this is the specification, I suggest it should be clearly stated in the [Official docs](https://ruby-doc.org/core-3.1.2/Range.html#method-i-size), avoiding the confusing expression "the count of elements", because "elements" are not unambiguously defined for Range of Float/Rational.




-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/