Skip to content

Comment on Ruby 2.1: Profiling Rubyparent

Comments

I don't write Ruby, but it's close enough to Perl that i can tell you. Precedence is the reason.

The first line with more explicit precedence is this:

    if( params[:user_id].present?) {
        @owner ||= User.find_by_login(params[:user_id]) 
    }
The second line is this:
    @owner ||= (
        User.find_by_login(params[:user_id]) if params[:user_id].present?
    )
In other words, the first version always ran the present? method, while the second version only did so if @owner was false.
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.