module ActiveModel::AttributeMethods
def _read_attribute(attr)
def _read_attribute(attr) __send__(attr) end
def attribute_method?(attr_name)
def attribute_method?(attr_name) respond_to_without_attributes?(:attributes) && attributes.include?(attr_name) end
def attribute_missing(match, *args, &block)
attribute method. If so, we tell +attribute_missing+ to dispatch the
+method_missing+ is called we check to see if there is a matching
+attribute_missing+ is like +method_missing+, but for attributes. When
def attribute_missing(match, *args, &block) __send__(match.target, match.attr_name, *args, &block) end
def matched_attribute_method(method_name)
Returns a struct representing the matching attribute method.
def matched_attribute_method(method_name) matches = self.class.send(:attribute_method_matchers_matching, method_name) matches.detect { |match| attribute_method?(match.attr_name) } end
def method_missing(method, *args, &block)
class belonging to the +clients+ table with a +master_id+ foreign key
It's also possible to instantiate related objects, so a Client
ActiveRecord::Base#attributes=.
the attributes hash -- except for multiple assignments with
Person#name and Person#name= and never directly use
methods. So a +Person+ class with a +name+ attribute can for example use
returned by attributes, as though they were first-class
Allows access to the object attributes, which are held in the hash
def method_missing(method, *args, &block) if respond_to_without_attributes?(method, true) super else match = matched_attribute_method(method.to_s) match ? attribute_missing(match, *args, &block) : super end 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 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. false else !matched_attribute_method(method.to_s).nil? end end