Could someone explain this?

#config/initializers/ar_attributes.rb

module ActiveRecord
  module AttributeMethods

      alias_method :ar_read_attribute, :read_attribute
      def read_attribute(attr_name)
        p "read_override"
        ar_read_attribute(attr_name)
      end

      alias_method :ar_write_attribute, :write_attribute
      def write_attribute(attr_name, value)
        raise 'You made it!'
      end
  end
end

In the Rails console:

>> person.read_attribute :name

"read_override"
=> "Joe"
>> person.write_attribute :name, "Bilal"
=> "Bilal"
>> person.read_attribute :name

"read_override"
=> "Bilal"
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to