Created
April 24, 2012 06:20
-
-
Save torkale/2477080 to your computer and use it in GitHub Desktop.
DRY using define
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class User < ActiveRecord::Base | |
| STATUS = { :active => 1, :inactive => 2, :pending => 3, :announce => 4, :curator => 5 } | |
| STATUS.each do |k, v| | |
| define_singleton_method(k) do | |
| where(:status => v) | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment