Consider some function foo:
def foo(input)
input * 2
end
How to get the max value of input for some array a?
a = [3, 5, 7, 9, 6]
Something like the following (which doesn’t work) should return 9:
a.max do |value|
foo(value)
end
How to do it?
Ruby 1.9.2
You need
max_by, notmax. http://www.ruby-doc.org/core-1.9.3/Enumerable.html#method-i-max_bymax:So
maxdoes take a block, but it doesn’t do what you expected it to.max_by: