I have @obj.items_per_page
, which is 20
at the beginning, and I want the method below to assign value to it only if many_items
is not nil
:
def fetch_it_baby (many_items = nil)
@obj.items_per_page = many_items
With the code above, even if many_items
is nil
, @obj.items_per_page
remains at 20
. Why? And is that "good" coding? Shouldn't I use something like
@obj.items_per_page = many_items || @obj.items_per_page
Or is there a third way? I don't feel completely comfortable with either way.
@obj.items_per_page if= many_items
– Brookins