• A Study in Array#Collect
    Stephen Chu talked about how to beautify statements like customers.collect { |customer| customer.name } in one of his posts . Dr. Nic also has a post talking about the same thing. It's very interesting to see so many people want to get away the cumbersome collect syntax and I am one of these people. To beautify the collect syntax when we need just one field such as customer.name . There are several ways:to use Stephen's syntax: customers.collect_name Dr. Nic's : customers.names And guess what, if you are using Rails, it comes with a Symbol extension...
    read more
  • Permalink: Tuesday, December 04, 2007 11:14 AM
    Posted by ywen | 0 Comments
    Filed under
  • When RSpec meets Validatable
    Jay Fields writes an excellent module called Validatable to provide a class who include the module the ActiveRecord like behavior. For example, you can say validates_presence_of :attribute etc. This page has the RDoc of the module. When I write RSpec for a Validatable class, I ended up writing a stattement like this: @email.validate_only("presence_of/body") @email.errors.on(:body).should_not be_nil Which is basically testing body is a required field. It works, but it looks complicated and hard to understand. The RSpec on Rails plugin provides a...
    read more
  • Permalink: Monday, November 12, 2007 10:36 AM
    Posted by ywen | 0 Comments
    Filed under , ,