DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Custom Accessors

04.02.2005
| 11714 views |
  • submit to reddit
        
class Song < ActiveRecord::Base
  # Uses an integer of seconds to hold the length of the song

  def length=(minutes)
    write_attribute("length", minutes * 60)
  end

  def length
    read_attribute("length") / 60
  end
end
    

Comments

Dan Rios replied on Thu, 2013/09/05 - 2:20pm

Dan Rios replied on Thu, 2013/08/15 - 9:12am

Dan Rios replied on Sat, 2013/06/15 - 4:58pm

Dan Rios replied on Thu, 2013/06/13 - 12:17am

 interesting http://www.sneakadeal.com/

Michael Molo replied on Fri, 2013/03/01 - 6:34pm