Skip to content

Instantly share code, notes, and snippets.

@itspriddle
Created January 5, 2014 02:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itspriddle/8263445 to your computer and use it in GitHub Desktop.
Save itspriddle/8263445 to your computer and use it in GitHub Desktop.
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