how is mongoid syntax implemented ?

16 views
Skip to first unread message

Jedrin

unread,
Oct 23, 2013, 1:52:09 PM10/23/13
to rubyonra...@googlegroups.com

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

Dheeraj Kumar

unread,
Oct 23, 2013, 9:30:28 PM10/23/13
to rubyonra...@googlegroups.com

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

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/0e81b056-62c2-403b-aed1-a4e6892a4648%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Josh Jordan

unread,
Oct 24, 2013, 2:00:16 PM10/24/13
to rubyonra...@googlegroups.com
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).
Reply all
Reply to author
Forward
0 new messages