Reputation: 695
I have RoR app, and I want to change some lines of my code to be more elegant.
foo = params[:customer][:language].nil? or params[:customer][:language].empty? ? 'es' : params[:customer][:language]
I try with
foo = params[:customer][:language] || 'es'
But it's not the same exactly.
Thanks in advance.
Upvotes: 2
Views: 1101
Reputation: 51181
You can use activesupport's Object#presence
method, like this:
foo = params[:customer][:language].presence || 'es'
Upvotes: 7