Forum: Ruby on Rails how is mongoid syntax implemented ?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
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).
This topic is locked and can not be replied to.