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

Alexey has posted 28 posts at DZone. View Full User Profile

Enums Emulation In Ruby

04.10.2011
| 2741 views |
  • submit to reddit
        Type = [V1 = 'v1', V2 = 'v2']

class EntryForm 
  include ActiveModel::Validation
  Remind = [Periodically = 'periodically', Once = 'once', Never = 'never']
  validate_inclusion_of :remind, :in => Remind
  before_save {
    if @remind == Periodically
     self.schedule_yaml = create_schedule(...).to_yaml
   ...
  }
...
end


_form.html.haml:

   ...
   f.select :remind, EntryForm::Remind
   ...