module ActiveModel::AttributeMethods::ClassMethods

def attribute_method_prefix(*prefixes, parameters: nil)

person.name # => nil
person.clear_name
person.name # => "Bob"
person.name = 'Bob'
person = Person.new

end
end
send("#{attr}=", nil)
def clear_attribute(attr)
private

define_attribute_methods :name
attribute_method_prefix 'clear_'
attr_accessor :name

include ActiveModel::AttributeMethods
class Person

at least the +attr+ argument.
An instance method #{prefix}attribute must exist and accept

#{prefix}attribute(#{attr}, *args, &block)

to

#{prefix}#{attr}(*args, &block)

Uses +method_missing+ and respond_to? to rewrite the method.
Declares a method available for all attributes with the given prefix.
def attribute_method_prefix(*prefixes, parameters: nil)
  self.attribute_method_matchers += prefixes.map! { |prefix| AttributeMethodMatcher.new(prefix: prefix, parameters: parameters) }
  undefine_attribute_methods
end