I have a method that has a boolean value as a parameter. I’m aware it’s better to avoid boolean values. Anyway in my case it’s most efficient way.
Well, here is a method:
def some_method(include_some_values = false)
#do some workcountries = []
if include_some_values
#do some additional work
end
#return value
end
calling (haml)
= form_for @address do |f|
= f.select :fied1, MyModel.some_method(true) #it's okay
However if I call it as
= f.select :fied1, MyModel.some_method true
or
= f.select :fied1, MyModel.some_method :true
or
= f.select :fied1, MyModel.some_method false
or
= f.select :fied1, MyModel.some_method :false
then it’s not going to work. Why?
Probably
is interpreted as:
So just use parenthesizes to avoid ambiguity.
PS:
:trueis a symbol, so there’s no reason to fiddle with symbols if your dealing with booleans.