ruby idiom a ||= b means?

L

Lars Christensen

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
 
D

Dave Bass

Ratnavel said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top