To find the length of a map in Ruby, you can use the length
, size
, or count
method. These methods are synonymous and can be used interchangeably. Here's an example:
main.rb117 chars5 lines
All three methods return the same result, which is the number of key-value pairs in the map. In the example above, the map has 3 key-value pairs, so each of the methods returns 3.
gistlibby LogSnag