What’s the best way to set the default value of an optional local
variable in a partial template?
In the past I’ve used
<% foo = default_value unless (defined? foo) %>
But ActionView::Base says not
to use (defined? foo) and instead use (local_assigns.has_key? :foo) thus
<% foo = default_value unless (local_assigns.has_key? :foo) %>
Some have suggested
<% foo ||= default_value %>
which has the benefit of compact syntax, but will override passed values
of nil and false. Some have also suggested
<% foo = default_value if local_assigns[:foo].nil? %>
which will override the passed value nil.
Are there other pros and cons to consider here? Are any of these
strictly preferred over the others
Thanks!
-Ben