# How is mongoid syntax implemented?

**URL:** <https://www.ruby-forum.com/t/how-is-mongoid-syntax-implemented/237094>\
**Category:** Rails\
**Created:** [October 23, 2013, 7:53pm UTC](https://www.ruby-forum.com/t/how-is-mongoid-syntax-implemented/237094 "2013-10-23T19:53:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [October 23, 2013, 7:53pm UTC](https://www.ruby-forum.com/t/how-is-mongoid-syntax-implemented/237094/1 "2013-10-23T19:53:08Z")

</div>

In mongoid, a ORM mapped database object is like below. The part “type:  
String” seems to me to not fit into any standard ruby syntax and I was  
curious how does mongoid implement that ?

class Step  
include Mongoid::Document

field :Label, type: String  
field :Descript, type: String  
field :ErrorText, type: String

embedded\_in :step\_data

end

---

<div class="post-metadata">

**Author:** ![Jedrin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/47e85d/32.png) [@Jedrin](https://www.ruby-forum.com/u/Jedrin)\
**Post date:** [October 24, 2013, 3:32am UTC](https://www.ruby-forum.com/t/how-is-mongoid-syntax-implemented/237094/2 "2013-10-24T03:32:29Z")

</div>

It’s the new hash syntax introduced in ruby 1.9.

---

<div class="post-metadata">

**Author:** ![Jedrin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/47e85d/32.png) [@Jedrin](https://www.ruby-forum.com/u/Jedrin)\
**Post date:** [October 24, 2013, 8:02pm UTC](https://www.ruby-forum.com/t/how-is-mongoid-syntax-implemented/237094/3 "2013-10-24T20:02:30Z")

</div>

That is valid hash syntax. You’re call a method with a signature like:

def field(field\_name, options = {})  
…  
end

field\_name is a symbol, options is a hash where the keys are symbols and  
the values are constants (class objects).
