Topic: Ruby return smaller of two values

Hi, is there any function in Ruby that can return smaller of two values, just like java Math.min(a,b)?

Thanks a lot.

Re: Ruby return smaller of two values

Yep, just use the min method of array:

[4,1].min
=> 1
Rob Anderton
TheWebFellas

Re: Ruby return smaller of two values

wa, that is really simple. Thanks a lot.

Re: Ruby return smaller of two values

Yeah, really simple. Thank you very much~~ By the way, i can not find the method in the ruby doc

Re: Ruby return smaller of two values

Ah, it lives in Enumerable not directly in Array, as you can do some fancy things with it smile

http://apidock.com/ruby/Enumerable/min
Rob Anderton
TheWebFellas