Skip to content

Instantly share code, notes, and snippets.

@divoxx
Created December 16, 2009 23:40
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 divoxx/258347 to your computer and use it in GitHub Desktop.
Save divoxx/258347 to your computer and use it in GitHub Desktop.
module SymbolWithArgs
def args
@args || []
end
def [](*args)
@args = args
self
end
end
class Symbol
include SymbolWithArgs
end
def show_only_to(user, *roles)
if roles.any? { |role| user.send("is_#{role}?", *role.args) }
yield
end
end
# This will only yield if one of this methods returns true:
# * user.is_admin?
# * user.is_manager_of(other_user)
# * user.is_employee_of(some_office)
show_only_to current_user, :admin, :manager_of[other_user], :employee_of[some_office] do
# some private stuff here
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment