Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

andand is a pretty nice tool when you're dealing with uncertain data. As well as the basic usage

    person.andand.occupation.andand.company.andand.billing_address
(which evaluates to nil if there's no person, or if they have no occupation, etc), my colleague pointed out the other day that you can pass it a block:

    Person.find(:name => "Bob").andand {|person| person.fire_out_of(cannon) }
which will perform a daring feat of acrobatics if Bob (a trained professional) is present, but safely do nothing if he isn't.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: