Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ippeiukai/c9ea3bd91d2b63eb5889 to your computer and use it in GitHub Desktop.
Save ippeiukai/c9ea3bd91d2b63eb5889 to your computer and use it in GitHub Desktop.
Have you ever wanted to use def_single_delegator from SingleForwardable but still continue to use `delegate` of ActiveSupport?
module UseSingleForwardableWithActiveSupport
extend ActiveSupport::Concern
included do
original_delegate_method = method(:delegate).unbind if self.respond_to?(:delegate)
extend SingleForwardable
if original_delegate_method.present?
# restore the delegate of ActiveSupport that has been overshadowed by SingleForwardable
define_singleton_method :delegate, original_delegate_method
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment