Skip to content

Instantly share code, notes, and snippets.

@huned
Created September 5, 2014 20:57
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 huned/e8da0e17de845c0d6102 to your computer and use it in GitHub Desktop.
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.
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