Created
September 5, 2014 20:57
-
-
Save huned/e8da0e17de845c0d6102 to your computer and use it in GitHub Desktop.
Monkey patch ActiveResource::Base.user so that it calls @user if user is callable, otherwise uses the default behavior.
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
module ActiveResource | |
class Base | |
class << self | |
# Monkey patch ActiveResource::Base.user a little. We want it to call | |
# @user if @user is callable, otherwise use the default behavior. | |
def user_with_lambda | |
if defined?(@user) && @user.respond_to?(:call) | |
@user.call(self) | |
else | |
user_without_lambda # default behavior | |
end | |
end | |
alias_method_chain :user, :lambda | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment