Forum: Ruby on Rails how is mongoid syntax implemented ?

6af47f6f8659cffca8a527f6f75b4e65?d=identicon&s=25 Jedrin (Guest)
on 2013-10-23 19:53
(Received via mailing list)
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

Ce5e201eca55d4f79d0ead9acc91d544?d=identicon&s=25 Dheeraj Kumar (Guest)
on 2013-10-24 03:32
(Received via mailing list)
It's the new hash syntax introduced in ruby 1.9.
5b50fec1e5bf39bb4d75b199130882f7?d=identicon&s=25 Josh Jordan (Guest)
on 2013-10-24 20:02
(Received via mailing list)
That is valid hash syntax. You're call a method with a signature like:

def field(field_name, options = {})

field_name is a symbol, options is a hash where the keys are symbols and
the values are constants (class objects).
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.