Hacker News new | ask | show | jobs
by riffraff 5192 days ago
this is not true:

    ||= expands to @variable = @variable || @other_variable
I am not sure if semantics of defined-or-assign operator changed in recent rubies, but ||= used to expand to

    foo or foo = bar.
Which is different in some edge cases, e.g.

    >> a= Hash.new(0)
    => {}
    >> a[:key] ||= :v
    => 0
    >> a
    => {}
    >> a[:key] =  a[:key] || :v
    => 0
    >> a
    => {:key=>0}
1 comments

As far as I know, this behaviour is still the same; changing it would be a breaking change for those edge cases.