Created
August 7, 2012 19:41
-
-
Save odigity/3288728 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
require 'mongoid' | |
def ArrayOf(klass) | |
array_klass_name = "#{klass}Array" | |
array_klass = Object.const_set(array_klass_name.to_sym, Class.new(Array)) | |
array_klass.class_eval do | |
def self.demongoize(obj) | |
new(obj.map {|e| klass.demongoize(e)}) | |
end | |
end | |
array_klass | |
end | |
class MyDoc | |
def initialize | |
@paragraphs = ArrayOf(String).new | |
end | |
end | |
d = MyDoc.new |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment