Clean way to assign value unless empty
- by atmorell
Hello,
I often need to assign a variable, if the source value is set. So far I have done it like this:
filters[:red] = params[:search][:red] unless params[:search][:red].nil?
This works but looks a bit clumsy. There must be a more DRY way of getting this result.
Any suggestions?
Best regards.
Asbjørn Morell.