Aimred Developer Blog May 2008 Archive
Sequel 2.0 Almost Here
Sequel 2.0 Release Candidate has just been released. All deprecated methods have been removed so it’s probably a good idea to check your existing code before porting over.
14th May Cape Town Ruby Brigade Meeting
Don’t forget the next meeting of the Cape Town Ruby Brigade takes place at 19:00 this Wednesday 14th May at the Bandwidth Barn in Cape Town. This months topic will be a report back on the Scotland on Rails conference. More details at the Cape Town Ruby Brigade Google group meeting page.
Instantiating With Sequel::Model
One nice thing about Sequel::Model is that it allows both hash and block instantiation of models.
1 values = { :name => "Bob Roberts" } 2 organisation = Organisation.new( values ) do |o| 3 o.name ||= random_organisation_name 4 o.email_address ||= random_organisation_email 5 o.phone_number ||= random_phone_number 6 end
The call to Organisation.new( values )
sets the
attributes from the hash and then using Ruby’s ||=
operator (remember a ||= b
is equivalent to a = a ||
b
) in the block we set any attributes not present in the
hash.