@
@
@granmer2015-11-12 22:05:08
ruby
@granmer, 2015-11-12 22:05:08

What does the ||= operator mean in ruby?

Unfortunately, I couldn't find the answer on ruby-doc.org and on the first pages of google.
Found in this context:

def permitted_params
            @permitted_params ||= declared(params, 
               include_missing: false)
end

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
JS, 2015-11-12
_

In this case, ||= means that if the variable @permitted_params is not assigned a value, i.e. it is equal to nil or false, then you need to assign declared(params, include_missing: false) to it, therefore @permitted_params = declared(params, include_missing: false).
Otherwise, if it has a value, nothing needs to be done.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question