π Parent Note
π You can add the same logic method to each attribute by write once
class Person < ActiveRecord::Base
attribute_method_suffix '_changed?'
attribute_method_suffix '_short?'
private
def attribute_changed?(attr)
...
end
def attribute_short?(attr)
send(attr).length < 10
end
end
person = Person.find(1)
person.name_changed? # => false
person.name = 'Hubert'
person.name_changed? # => true
person.name_short? # => true
π attribute_method_suffix
Top comments (0)