class Adequack::Core
Attributes
duck[RW]
interface[RW]
Public Class Methods
implements(object, interface)
click to toggle source
# File lib/adequack/core.rb, line 4 def self.implements(object, interface) new(object, interface).send(:validate_ducktype) end
new(duck, interface)
click to toggle source
# File lib/adequack/core.rb, line 10 def initialize(duck, interface) self.duck = duck self.interface = interface end
Private Instance Methods
check_method_implementation(methods, instance = false)
click to toggle source
# File lib/adequack/core.rb, line 22 def check_method_implementation(methods, instance = false) methods.each do |method| if instance name = method defined = duck.method_defined?(method) else name = "self.#{method}" defined = duck.respond_to?(method) end raise InterfaceImplementationError, "object does not respond to '#{name}' method" unless defined end end
get_methods(methods)
click to toggle source
# File lib/adequack/core.rb, line 39 def get_methods(methods) methods - Object.methods end
validate_ducktype()
click to toggle source
# File lib/adequack/core.rb, line 15 def validate_ducktype check_method_implementation(get_methods interface.public_methods) check_method_implementation( get_methods(interface.public_instance_methods), true ) end