From: hanmac@... Date: 2017-04-24T07:22:34+00:00 Subject: [ruby-core:80842] [Ruby trunk Feature#13495] add Range#count as an alias to Range#size Issue #13495 has been updated by Hanmac (Hans Mackowiak). we can't do that. Enumerable#count does can take a block with you can define that you want to count. ~~~ ruby (1..4).count(&:even?) #=> 2 ~~~ so we can't make Range#count be an alias for Range#size without breaking other stuff. ---------------------------------------- Feature #13495: add Range#count as an alias to Range#size https://bugs.ruby-lang.org/issues/13495#change-64446 * Author: AaronLasseigne (Aaron Lasseigne) * Status: Open * 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: