Ruby Range is a very powerful class. The three following methods provide often overlooked features when dealing with collections.

>> ('a'..'z').max
#=> z
 
>> ('a'...'z').max
#=> y
>> ('a'..'z').min
#=> a
 
>> ('a'...'z').min
#=> b
>> ('a'..'z').size
=> nil
# WAT!
 
>> ('a'..'z').count
=> 26

Use count versus size when dealing with non-integer collections.

:)

Leave a Reply

Your email address will not be published. Required fields are marked *