Created
December 12, 2012 13:27
-
-
Save anonymous/4267712 to your computer and use it in GitHub Desktop.
Define hookable API in module that’s included, this way other clients can include a module that overrides those hooks. Because including modules inserts the methods in the ancestor lookup chain (i.e. the power of Ruby), this allows the use of super etc.
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 API | |
def execute(command) | |
puts command | |
end | |
end | |
class Downloader | |
include API | |
def download! | |
execute('git clone URL') | |
end | |
end | |
d = Downloader.new | |
d.download! | |
module APIOverrides | |
def execute(command) | |
puts "\nExecuting:" | |
super | |
end | |
end | |
class Downloader | |
include APIOverrides | |
end | |
d.download! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment