Using conditional assignment in Ruby
1 2 a = 'crazy' 3 a ||= 'attentive' 4 puts 'my current mood is ' + a
=> my current mood is crazy
1 2 a ||= 'attentive' 3 puts 'my current mood is ' + a
=> my current mood is attentive
References:
- Ruby Programming/Syntax/Operators [wikibooks.org]
- DABlog A short-circuit (||=) edge case [rubypal.com]