From: aaron.lasseigne@... Date: 2017-04-25T14:49:33+00:00 Subject: [ruby-core:80861] [Ruby trunk Feature#13495] add Range#count as an alias to Range#size Issue #13495 has been updated by AaronLasseigne (Aaron Lasseigne). > PS: "Enumerable does not have size" is incorrect. Enumerable have a size method, although it may return nil if the result can not be calculated lazily. I don't think that's true. The docs don't show it and it doesn't get added when you include `Enumerable`. ~~~ [1] pry(main)> class Foo [1] pry(main)* include Enumerable [1] pry(main)* end => Foo [2] pry(main)> Foo.methods.include?(:size) => false [3] pry(main)> ~~~ Aside from that, it means you can't create functions that are designed to work with Enumerable classes and depend on anything to get a proper size/length/count from them. ---------------------------------------- Feature #13495: add Range#count as an alias to Range#size https://bugs.ruby-lang.org/issues/13495#change-64469 * Author: AaronLasseigne (Aaron Lasseigne) * Status: Rejected * Priority: Normal * Assignee: * Target version: ---------------------------------------- For infinite ranges you can't call `count`, you have to call `size`. ~~~ irb> (1..Float::INFINITY).count # have to interrupt to stop it irb> (1..Float::INFINITY).size => Infinity ~~~ The problem with this is that Range is an Enumerable. Enumerable does not have `size` it has `count`. So, if you want to implement a method for any Enumerable and you want to check the number of items you can't rely on `count`. Instead you have to do: ~~~ enum_count = begin size rescue NameError count end ~~~ Making Range#count as an alias of Range#size would allow people to make methods for Enumerable classes that rely on `count`. -- https://bugs.ruby-lang.org/ Unsubscribe: