How is mongoid syntax implemented?

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

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

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).

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs