Possible Duplicate:
What does ||= mean in Ruby?
I’m new to ruby and I saw this being used in one of the answers here:
RACK_ENV = ENV['ENVIRONMENT'] ||= 'test'
I couldn’t find any reference to the ||= operator…
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
what does || do? If you have a and b then
a || bis true if and only if either a or b is true. It is the same with ||= this operator combines two operations ‘=’ and ‘||’. Soa ||= bis equivelent toc || c = bEDIT: so in your context ENV[‘ENVIRONMENT’] ||= ‘test’ means that if ENV[‘ENVIRONMENT’] is not nil and not false it will preserve its value, otherwise it will become ‘test’ and after that the new value of ENV[‘ENVIRONMENT’] is assigned to RACK_ENV