I do this a lot in javascript
some_var || some_var = function(){ return "blah"}();
I'm wondering what the equivalent in ruby might be so I can do
some_var ||= # sequence of operations
edit
the Proc.new.call has been brought to my attention, but I also just came across this in someone's code:
a ||= begin
# do some stuff
# return some stuff
end
Is this functionally equivalent to using a Proc.new.call ??
edit2 People seem to be confused as to what I'm trying to achieve. Imagine this in javascript:
function someExpensiveFunction(){
# do some really expensive stuff
return "some expensive calculations"
}
a || a = someExpensiveFunction();
Obviously sets a once... calls expensive function once... In this case I don't care about scoping, I just need my return value to be a calculated sequence of events rather than a single value.
I'm pretty sure my example above a ||= begin; ... end; is equivalent...