Intercepting activerecord attributes
# So, you wrote a Rails application to track Marathon events. In a sudden 
# change of heart, you pick up your company and move it from the United 
# States to Germany. Why rewrite your app to handle metric distances? 
# Rails provides a solution: write_attribute and read_attribute. 

class Marathon < ActiveRecord::Base
  def distance=(meters)
    write_attribute(:distance, meters * 1609.344)
  end

  def distance
    read_attribute(:distance) / 0.000621371192
  end
end
Language Ruby / Tagged with rails, activerecord