Skip to content

Instantly share code, notes, and snippets.

@gevans
Created May 6, 2014 04:10
Show Gist options
  • Save gevans/d070ca040da979a2b03f to your computer and use it in GitHub Desktop.
Save gevans/d070ca040da979a2b03f to your computer and use it in GitHub Desktop.

Revisions

  1. gevans created this gist May 6, 2014.
    22 changes: 22 additions & 0 deletions hash_with_indifferent_access.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    module Extensions
    module HashWithIndifferentAccess

    def mongoize
    ::HashWithIndifferentAccess.mongoize(self)
    end

    module ClassMethods

    def demongoize(object)
    ::Hash.demongoize(object).try(:with_indifferent_access)
    end

    def mongoize(object)
    ::Hash.mongoize(object)
    end
    end # ClassMethods
    end # HashWithIndifferentAccess
    end # Extensions

    ::HashWithIndifferentAccess.__send__(:include, Extensions::HashWithIndifferentAccess)
    ::HashWithIndifferentAccess.extend(Extensions::HashWithIndifferentAccess::ClassMethods)