Created
May 22, 2018 11:44
-
-
Save nunosilva800/4ba376eecc838fee38858f7eac9ea668 to your computer and use it in GitHub Desktop.
ruby interfaces example
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 APIProfile | |
def profile | |
raise NotImplementedError.new("You must implement '#{__method__}'.") | |
end | |
end | |
module APIAddress | |
def address | |
raise NotImplementedError.new("You must implement '#{__method__}'.") | |
end | |
end | |
class APIProviderA | |
include APIProfile | |
end | |
class APIProviderB | |
include APIProfile | |
include APIAddress | |
end | |
# --- | |
> APIProviderA.new.respond_to? :profile | |
=> true | |
> APIProviderA.new.profile | |
NotImplementedError: You must implement 'profile'. | |
> APIProviderA.new.respond_to? :address | |
=> false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment