I'm implementing authorization in an app according to this Railscasts episode.
In one of the instance methods, Ryan Bates is using the method .call and I don't understand what exactly it is doing. This is the code for the whole model. And this is the particular method:
def allow?(controller, action, resource = nil)
allowed = @allow_all || @allowed_actions[[controller.to_s, action.to_s]]
allowed && (allowed == true || resource && allowed.call(resource))
end
The resource argument is an instance object and the local variable allowed
is supposed to be a boolean value.
call
evaluates the proc or method receiver passing its arguments to it.It is used to call back a piece of code that has been passed around as an object.