minmax

enum.minmax â [min, max]
enum.minmax { |a, b| block } â [min, max]
Instance Public methods

Returns two elements array which contains the minimum and the maximum value in the enumerable. The first form assumes all objects implement Comparable; the second uses the block to return a <=> b.

a = %w(albatross dog horse)
a.minmax                                  #=> ["albatross", "horse"]
a.minmax { |a, b| a.length <=> b.length } #=> ["dog", "albatross"]
doc_ruby_on_rails
2015-04-05 01:23:56
Comments
Leave a Comment

Please login to continue.