I'd even be tempted split it into two private methods:
def strip_whitespaces
%w(name description aliases).each do |attribute|
strip_whitespace_from attribute
end
end
def strip_whitespace_from(attr)
send("#{attr}=", send(attr).split.join(" ")) if attribute_present?(attr)
end
Note that you don't need to do self.send
- the self
is implied - and also you don't need to do send("#{attr}")
because that interpolation achieves nothing, you can just do send(attr)
.