Created
August 7, 2012 20:24
-
-
Save odigity/3289008 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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