module ActiveModel::AttributeMethods::ClassMethods
def attribute_method_suffix(*suffixes, parameters: nil)
person.name # => "Bob"
person.name = 'Bob'
person = Person.new
end
end
send(attr).length < 5
def attribute_short?(attr)
private
define_attribute_methods :name
attribute_method_suffix '_short?'
attr_accessor :name
include ActiveModel::AttributeMethods
class Person
least the +attr+ argument.
An attribute#{suffix} instance method must exist and accept at
attribute#{suffix}(#{attr}, *args, &block)
to
#{attr}#{suffix}(*args, &block)
Uses +method_missing+ and respond_to? to rewrite the method.
Declares a method available for all attributes with the given suffix.
def attribute_method_suffix(*suffixes, parameters: nil) self.attribute_method_matchers += suffixes.map! { |suffix| AttributeMethodMatcher.new(suffix: suffix, parameters: parameters) } undefine_attribute_methods end