Created
January 10, 2012 18:06
-
-
Save paneq/1590291 to your computer and use it in GitHub Desktop.
Ruby interface
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
module Interface | |
def ===(obj) | |
self.instance_methods.all?{|m| obj.respond_to?(m)} | |
end | |
end | |
module IService | |
extend Interface | |
def start | |
end | |
def stop | |
end | |
end | |
class Object | |
def interface(*params) | |
end | |
end | |
class Nginx | |
interface IService | |
def start | |
puts "starting nginx" | |
end | |
def stop | |
puts "starting nginx" | |
end | |
end | |
puts IService === Nginx.new |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment