Sha256: 947ef1e4e70bc3fd55f0b5b02bea946a7c38d4c49bcebeccc28c74378dd26080

Contents?: true

Size: 683 Bytes

Versions: 1

Compression:

Stored size: 683 Bytes

Contents

module Inspector
  module Constraints
    class Predicate
      include Constraint

      def initialize(method, *args, &block)
        @method = method
        @args = args
        @block = block
      end

      def valid?(actual)
        result = false

        begin
          result = actual.__send__("#{@method}?", *@args, &@block)
        rescue NameError
        end

        begin
          result  = actual.__send__("#{@method}s?", *@args, &@block)
          @method = "#{@method}s"
        rescue NameError
        end

        return result
      end

      def to_s
        "be_#{@method}"
      end

      def inspect
        "#<#{@method}>"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
object-inspector-0.1.0 lib/inspector/constraints/predicate.rb