Skip to content

Instantly share code, notes, and snippets.

Created December 12, 2012 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/4267712 to your computer and use it in GitHub Desktop.
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.
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