[Ruby] unless block on one line

ben wiseley wiseleyb at gmail.com
Fri Jan 26 11:53:53 PST 2007


On this topic ... is there a better way to do things like this where Contact
is just a straight class (doesn't inherit from anything like Model)

    @contact = Contact.new
    @contact.name = params[:contact][:name]
    @contact.email = params[:contact][:email]
    @contact.subject = params[:contact][:subject]
    @contact.message = params[:contact][:message]

Anything like "update_attributes" for normal classes?

-ben


On 1/26/07, Andrew Stewart <boss at airbladesoftware.com> wrote:
>
>
> > 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
> _______________________________________________
> Ruby at zenspider.com - Seattle.rb non-commercial list
> http://www.zenspider.com/seattle.rb
> http://www.zenspider.com/mailman/listinfo/ruby
>


More information about the Ruby mailing list