Skip to content

Instantly share code, notes, and snippets.

@m0wfo
Created December 27, 2008 16:03
Show Gist options
  • Save m0wfo/40271 to your computer and use it in GitHub Desktop.
Save m0wfo/40271 to your computer and use it in GitHub Desktop.
class Integer
def round_to_nearest(*args)
most = self % args[0]
most > (args[0]/2)? self - most + args[0] : self - most
end
end
anumber = 349
p anumber.round_to_nearest(50)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment