Skip to content

Instantly share code, notes, and snippets.

@odigity
Created August 7, 2012 20:24
Show Gist options
  • Save odigity/3289008 to your computer and use it in GitHub Desktop.
Save odigity/3289008 to your computer and use it in GitHub Desktop.
module Mongoid
module Document
module ClassMethods
def HashOf(klass)
hash_klass_name = "#{klass}Hash"
hash_klass = Object.const_set(hash_klass_name.to_sym, Class.new(Hash))
hash_klass.class_eval do
define_singleton_method(:demongoize) do |obj|
new( obj.merge(obj) { |k,v| k, klass.demongoize(v) } )
end
end
hash_klass
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment