Assuming that you want to find the range of all the values in a Ruby hash (also known as a map), you can retrieve all the values of the hash using the values
method, then use the min
and max
methods to find their minimum and maximum:
main.rb79 chars4 lines
Alternatively, you can use the Enumerable
module's minmax
method to get an array of the minimum and maximum values, then calculate the range:
main.rb114 chars5 lines
Both approaches will give you the range of all values in the hash.
gistlibby LogSnag