In a question I've previously answered, I used an association extension to override a HABTM collection's append (<<
) method (Also, a similar question):
has_and_belongs_to_many(:countries) do
def <<(country)
if [*country].all? {|c| c.is_a?(String) }
countries = Country.where(:code => country)
concat(*countries)
else
concat(country)
end
end
end
This is probably not encouraged, but my question is, how can one override, if even possible, the assignment operator, so I can do countries = ['IL', 'US']
with the same results?