Created
July 1, 2014 09:57
-
-
Save kalleth/a6142702dc2a8834320c to your computer and use it in GitHub Desktop.
delegation_chain for SimpleDelegator objects to allow easy inspection of their delegation chain
This file contains hidden or 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
class SimpleDelegator | |
def delegation_chain | |
[self].tap do |output| | |
object = self | |
while object.respond_to?("__getobj__") | |
object = object.__getobj__ | |
output << object | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment