Method: ActiveModel::AttributeMethods#method_missing
- Defined in:
- lib/active_model/attribute_methods.rb
#method_missing(method) ⇒ Object
Allows access to the object attributes, which are held in the hash returned by attributes, as though they were first-class methods. So a Person class with a name attribute can for example use Person#name and Person#name= and never directly use the attributes hash – except for multiple assignments with ActiveRecord::Base#attributes=.
It’s also possible to instantiate related objects, so a Client class belonging to the clients table with a master_id foreign key can instantiate master through Client#master.
507 508 509 510 511 512 513 514 |
# File 'lib/active_model/attribute_methods.rb', line 507 def method_missing(method, ...) if respond_to_without_attributes?(method, true) super else match = matched_attribute_method(method.name) match ? attribute_missing(match, ...) : super end end |