I want to use min(5,10), or Math.max(4,7). Are there functions to this effect in Ruby?
I want to use min(5,10) , or Math.max(4,7) . Are there functions to this
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
.min.maxThey come from the Enumerable module, so anything that includes
Enumerablewill have those methods available.v2.4 introduces own
Array#minandArray#max, which are way faster than Enumerable’s methods because they skip calling#each..minmax@nicholasklick mentions another option,
Enumerable#minmax, but this time returning an array of[min, max].