S
Sam Kong
Hi,
I find myself to use the following idiom frequently.
def foo i
return @cache if @cache
@cache = some_method_that_takes_long_time(i)
end
I like the post-modifying if statement.
But I feel uncomfortable with calling @cache twice.
I wish this worked.
return v if v = @cache #=> undefined local variable or method `v'
This works but it's long.
if v = @cache
return v
end
Maybe this is a compromise.
if v = @cache then return v end
I want "return statement" to stand out.
Post-modification looks better for that.
So I call @cache twice.
How do you do it?
Sam
I find myself to use the following idiom frequently.
def foo i
return @cache if @cache
@cache = some_method_that_takes_long_time(i)
end
I like the post-modifying if statement.
But I feel uncomfortable with calling @cache twice.
I wish this worked.
return v if v = @cache #=> undefined local variable or method `v'
This works but it's long.
if v = @cache
return v
end
Maybe this is a compromise.
if v = @cache then return v end
I want "return statement" to stand out.
Post-modification looks better for that.
So I call @cache twice.
How do you do it?
Sam