From: Ratnavel P S on
What does the ruby idiom a ||= b mean?

Thanks,
Ratnavel
--
Posted via http://www.ruby-forum.com/.

From: Rob Biedenharn on

On Jul 1, 2008, at 12:31 AM, Ratnavel P S wrote:

> What does the ruby idiom a ||= b mean?
>
> Thanks,
> Ratnavel

It is like:
a || a = b
See David A. Black's Blog
http://dablog.rubypal.com/2008/3/25/a-short-circuit-edge-case

-Rob

P.S. Please don't ask the same question on both Rails and Ruby lists/
forums.

Rob Biedenharn http://agileconsultingllc.com
Rob(a)AgileConsultingLLC.com



From: Lars Christensen on
On Jul 1, 6:49 am, Rob Biedenharn <R...(a)AgileConsultingLLC.com> wrote:
> On Jul 1, 2008, at 12:31 AM, Ratnavel P S wrote:
>
> > What does the ruby idiom a ||= b mean?
>
> It is like:
>         a || a = b

In english, thats: If a is nil or false, then leave it, else assign a
= b.

Often used instead of code like this:

if a.nil? then
a = b
end
From: Dave Bass on
Ratnavel P S wrote:
> What does the ruby idiom a ||= b mean?

It's commonly used to assign default values to things.
This idiom is also very common in Perl, which is presumably where it
came from.
--
Posted via http://www.ruby-forum.com/.

From: Ruby Freak on
This has been discussed nearly to death at:
http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/fe4fbc48e19105cd/bf7f73380e285aff?lnk=gst&q=Or+equal#bf7f73380e285aff