You can get the total count of the number of elements in a Ruby array by using the
puts [1, 2, 3].length #=> 3 puts [1, 2, 3].count #=> 3 puts [1, 2, 3].size #=> 3
puts .length #=> 0 puts .count #=> 0 puts .size #=> 0
For the purpose of getting the count of elements in an array, all three methods will produce the same result.
Array#size is merely an alias for
Array#count method can be used in two other ways (besides counting the total number of items in an array):
Hope you found this post useful. It was published . Please show your love and support by sharing this post.