Never been to DZone Snippets before?

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

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

BlankSlate: Clean an object class to its bare minimum methods in Ruby

From http://onestepback.org/index.cgi/Tech/Ruby/BlankSlate.rdoc

class BlankSlate
   instance_methods.each { |m| undef_method m unless m =~ /^__/ }
end

custom accessors

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
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS