Skip to content

Instantly share code, notes, and snippets.

@akinsgre
Created January 9, 2012 02:45
Show Gist options
  • Save akinsgre/1580740 to your computer and use it in GitHub Desktop.
Save akinsgre/1580740 to your computer and use it in GitHub Desktop.
class ContactMethod < ActiveRecord::Base
validates_presence_of :name
def self.select_options
descendants.map { |c| c.to_s }.sort
end
end
class Phone < ContactMethod
end
class TextMsg < ContactMethod
end
[gakins@Somnambulist contact]$ rails c
Loading development environment (Rails 3.1.3)
ruby-1.9.2-p290 :001 > ContactMethod.select_options
=> []
ruby-1.9.2-p290 :002 > Phone.new
=> #<Phone id: nil, name: nil, type: 0, created_at: nil, updated_at: nil>
ruby-1.9.2-p290 :003 > TextMsg.new
=> #<TextMsg id: nil, name: nil, type: 0, created_at: nil, updated_at: nil>
ruby-1.9.2-p290 :004 > ContactMethod.select_options
=> ["Phone", "TextMsg"]
ruby-1.9.2-p290 :005 >
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment