Skip to content

Instantly share code, notes, and snippets.

@cawel
Created May 3, 2010 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cawel/388607 to your computer and use it in GitHub Desktop.
Save cawel/388607 to your computer and use it in GitHub Desktop.
module SmartHippo::MonkeyPatches::Enumerable
def self.included(base)
base.class_eval do
# snap to nearest value in a collection of values
def snap_from value
value = value.to_i
self.sort_by{|i| (i - value).abs }.first
end
end
end
end
module Enumerable
include SmartHippo::MonkeyPatches::Enumerable
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment