Created
February 8, 2011 16:49
-
-
Save avescodes/816726 to your computer and use it in GitHub Desktop.
Read through this snippet for a few minutes then walk us through what you think it does
This file contains 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 Permit < ActiveRecord::Base | |
# ... snip* | |
# Assume "def model" exists elsewhere in the class. | |
def to_ability | |
modes = [:create, :read, :update, :destroy].select do |mode| | |
self.send(:"can_#{mode}?") | |
end | |
object = model | |
unless self[:model_id].nil? | |
if object.is_a? Register | |
model_id = self[:model_id] | |
else | |
model_id = self[:model_id].to_i # ActiveRecord doesn't like string ids | |
end | |
options = {:id => model_id } | |
object = object.class | |
end | |
return [modes, object, options || {}] | |
end | |
# ... snip* | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment