Method: Mongoid::Fields::ClassMethods#field
- Defined in:
- lib/mongoid/fields.rb
#field(name, options = {}) ⇒ Field
Defines all the fields that are accessible on the Document For each field that is defined, a getter and setter will be added as an instance method to the Document.
483 484 485 486 487 488 489 490 491 |
# File 'lib/mongoid/fields.rb', line 483 def field(name, = {}) named = name.to_s Validators::Macro.validate(self, name, ) added = add_field(named, ) descendants.each do |subclass| subclass.add_field(named, ) end added end |