SameShirtEveryDay.com

Personal blog of the one called Alex Gorbatchev, from Toronto, Canada.

Where’s Math.min and Math.max in Ruby?

Posted on June 9th, 2007 by Alex Gorbatchev. In Ruby. 1 comment so far...

Maybe it’s just me and I don’t know where to look, but this isn’t something I’m interested in spending 30 minutes looking for.

module Math
  def self.max(a, b)
    a > b ? a : b
  end

  def self.min(a, b)
    a < b ? a : b
  end
end
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

One comments so far...

  1. Alpar

    You can use [a, b].max or [a, b].min.

    This answer is from: http://stackoverflow.com/questions/1359370/how-do-you-find-a-min-max-with-ruby

Leave a Reply

Allowed tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> , rel="nofollow" in use - no link dropping, no keywords or domains as names; do not spam, and do not advertise!

home
Subscribe to this blog Follow me on Twitter My bookmarks on Delicious My photography on Flickr