Created
January 5, 2014 02:16
-
-
Save itspriddle/8263445 to your computer and use it in GitHub Desktop.
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 Bitmask | |
ACTIONS = %W(create read update destroy) | |
def self.dump(actions) | |
(actions & ACTIONS).sum { |a| 1 << ACTIONS.index(a) } | |
end | |
def self.load(mask) | |
ACTIONS.reject { |a| ((mask || 0) & 1 << ACTIONS.index(a)).zero? } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment