Hacker News new | past | comments | ask | show | jobs | submit login

I use this to memoize instance vars from time to time, whenever nil could be considered valid

    return x if defined? x

    x = ingest_stock_market
`defined?` won't evaluate the parameter either which is nice whereas things like blank? present? and presence do



> return x if defined? x

It's a natural pattern, and translates with obvious changes to Perl, but still `x = defined? x ? x : y` is longer than `x //= y`, so all I was meaning to say in my original comment was that I was surprised that Ruby didn't borrow the latter from Perl.




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

Search: