Skip to content

Instantly share code, notes, and snippets.

@paneq
Created January 10, 2012 18:06
Show Gist options
  • Save paneq/1590291 to your computer and use it in GitHub Desktop.
Save paneq/1590291 to your computer and use it in GitHub Desktop.
Ruby interface
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