module Interface # General basis for an interface NotImplemented = Class.new ArgumentError # Indicates a target object does not implement the checked interface MissingMethod = Class.new ArgumentError # Raised when a method from the interface is not supported by the implementation InvalidReturn = Class.new ArgumentError # Raised when the target return value does not meet the expectaions on it. # Check if an interface is implemented on a target # Checked by seeing if the interface module is fronting the ancesor chain def implemented_on?(target) target.class.ancestors.first == self end # Enforce a target implements the interface def required_on!(target) raise NotImplemented unless self.implemented_on? target end end