method
max
![Moderate documentation Importance_2](https://d2vfyqvduarcvs.cloudfront.net/images/importance_2.png?1349367920)
max()
public
Returns the object in enum with the maximum value. The first form assumes all objects implement Comparable; the second uses the block to return a <=> b.
a = %w(albatross dog horse) a.max #=> "horse" a.max { |a, b| a.length <=> b.length } #=> "albatross"
Register or
log in
to add new notes.
Mange -
February 16, 2009
MattStopa -
March 15, 2012
![Default_avatar_30](https://www.gravatar.com/avatar/1b2792536d87aa21bc739c14980fa103?size=30&default=http://apidock.com/images/default_avatar_30.png)
2 thanks
Capping values
This method is very useful when you want to cap values:
# minimum ≤ value value = [input.to_i, minimum].max # value ≤ maximum value = [input.to_i, maximum].min # minimum ≤ value ≤ maximum value = [ [input.to_i, minimum].max, maximum ].min # Practical example: Make sure destination is within container destination.x = [ [current.x + current.velocity.x, 0].max, container.width ].min destination.y = [ [current.y + current.velocity.y, 0].max, container.height ].min
![Default_avatar_30](https://www.gravatar.com/avatar/bf2741e5fba213cd501b0c64fdffad3f?size=30&default=http://apidock.com/images/default_avatar_30.png)
0 thanks