module ActiveModel::AttributeMethods

def attribute_method?(attr_name)

def attribute_method?(attr_name)
  attributes.include?(attr_name)
end

def guard_private_attribute_method!(method_name, args)

prevent method_missing from calling private methods with #send
def guard_private_attribute_method!(method_name, args)
  if self.class.private_method_defined?(method_name)
    raise NoMethodError.new("Attempt to call private method", method_name, args)
  end
end

def match_attribute_method?(method_name)

The struct's attributes are prefix, base and suffix.
Returns a struct representing the matching attribute method.
def match_attribute_method?(method_name)
  self.class.send(:attribute_method_matchers).each do |method|
    if (match = method.match(method_name)) && attribute_method?(match.attr_name)
      return match
    end
  end
  nil
end

def method_missing(method_id, *args, &block)

instantiate master through Client#master.
belonging to the clients table with a +master_id+ foreign key can
It's also possible to instantiate related objects, so a Client class

or 0.
Milestone#completed? to test that the completed attribute is not +nil+
with ActiveRecord#attributes=. A Milestone class can also ask
and never directly use the attributes hash -- except for multiple assigns
Person class with a name attribute can use Person#name and Person#name=
@attributes hash, as though they were first-class methods. So a
Allows access to the object attributes, which are held in the
def method_missing(method_id, *args, &block)
  method_name = method_id.to_s
  if match = match_attribute_method?(method_name)
    guard_private_attribute_method!(method_name, args)
    return __send__(match.target, match.attr_name, *args, &block)
  end
  super
end

def missing_attribute(attr_name, stack)

def missing_attribute(attr_name, stack)
  raise ActiveModel::MissingAttributeError, "missing attribute: #{attr_name}", stack
end

def respond_to?(method, include_private_methods = false)

def respond_to?(method, include_private_methods = false)
  if super
    return true
  elsif !include_private_methods && super(method, true)
    # If we're here then we haven't found among non-private methods
    # but found among all methods. Which means that the given method is private.
    return false
  elsif match_attribute_method?(method.to_s)
    return true
  end
  super
end