module ActiveModel::AttributeMethods::ClassMethods
def define_attribute_method(attr_name, _owner: generated_attribute_methods)
person.name # => "Bob"
person.name = 'Bob'
person = Person.new
end
end
send(attr).length < 5
def attribute_short?(attr)
private
define_attribute_method :name
# attribute_method_affix declarations.
# attribute_method_prefix, attribute_method_suffix or
# Call to define_attribute_method must appear after the
attribute_method_suffix '_short?'
attr_accessor :name
include ActiveModel::AttributeMethods
class Person
method, or they will not hook in.
+define_attribute_method+ after you define any prefix, suffix or affix
To use, pass an attribute name (as string or symbol). Be sure to declare
ActiveModel::AttributeMethods.
Declares an attribute that should be prefixed and suffixed by
def define_attribute_method(attr_name, _owner: generated_attribute_methods) ActiveSupport::CodeGenerator.batch(_owner, __FILE__, __LINE__) do |owner| attribute_method_matchers.each do |matcher| method_name = matcher.method_name(attr_name) unless instance_method_already_implemented?(method_name) generate_method = "define_method_#{matcher.target}" if respond_to?(generate_method, true) send(generate_method, attr_name.to_s, owner: owner) else define_proxy_call(owner, method_name, matcher.target, matcher.parameters, attr_name.to_s, namespace: :active_model_proxy) end end end attribute_method_matchers_cache.clear end end