Skip to content

Instantly share code, notes, and snippets.

@sclinede
Last active August 29, 2015 14:03
Show Gist options
  • Save sclinede/6577ab6abdde206ead3a to your computer and use it in GitHub Desktop.
Save sclinede/6577ab6abdde206ead3a to your computer and use it in GitHub Desktop.
# coding: utf-8
class MeasureUnitCache
include Singleton
def self.find_similar_to_name(name)
instance.data[name]
end
private
def data
unless defined? @data
@data = {}
MeasureUnit.all.each_with_object(@data) { |mu, result| result[mu.name.gsub(/\.+$/, '')] = mu }
end
@data
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment