Skip to content

Instantly share code, notes, and snippets.

@avescodes
Created February 8, 2011 16:49
Show Gist options
  • Save avescodes/816726 to your computer and use it in GitHub Desktop.
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
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