[Ruby] unless block on one line

Andrew Stewart boss at airbladesoftware.com
Fri Jan 26 06:35:27 PST 2007


> is there a way of expressing this on one line?
>
> unless row.at(7).nil?
>    this_row[:print_date] = row.at(7).date
> end

You were close!  This is what you need to do:

this_row[:print_date] = row.at(7).date unless row.at(7).nil?

Regards,
Andy Stewart


More information about the Ruby mailing list