Sha256: 951a328ed07ca0a85faa3f71d68d308d15c889c7ad1c7a21c8e468ccfde3135e

Contents?: true

Size: 612 Bytes

Versions: 7

Compression:

Stored size: 612 Bytes

Contents

module RR
  module Expectations
    module WildcardMatchers
      class DuckType
        attr_accessor :required_methods

        def initialize(*required_methods)
          @required_methods = required_methods
        end

        def wildcard_match?(other)
          return true if self == other
          required_methods.each do |m|
            return false unless other.respond_to?(m)
          end
          return true
        end

        def ==(other)
          return false unless other.is_a?(self.class)
          self.required_methods == other.required_methods
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rr-0.1.2 lib/rr/expectations/wildcard_matchers/duck_type.rb
rr-0.1.0 lib/rr/expectations/wildcard_matchers/duck_type.rb
rr-0.1.6 lib/rr/expectations/wildcard_matchers/duck_type.rb
rr-0.1.1 lib/rr/expectations/wildcard_matchers/duck_type.rb
rr-0.1.4 lib/rr/expectations/wildcard_matchers/duck_type.rb
rr-0.1.5 lib/rr/expectations/wildcard_matchers/duck_type.rb
rr-0.1.3 lib/rr/expectations/wildcard_matchers/duck_type.rb