What does the ruby idiom a ||= b mean?
Thanks,
Ratnavel
···
--
Posted via http://www.ruby-forum.com/.
What does the ruby idiom a ||= b mean?
Thanks,
Ratnavel
--
Posted via http://www.ruby-forum.com/.
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@AgileConsultingLLC.com
On Jul 1, 2008, at 12:31 AM, Ratnavel P S wrote:
What does the ruby idiom a ||= b mean?
Thanks,
Ratnavel
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/\.
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
On Jul 1, 6:49 am, Rob Biedenharn <R...@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
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