Sha256: eeb18f8b647ae8d199e35a7fd6bc8b96adbf4a642184b3f1ae0b559f3c654051

Contents?: true

Size: 438 Bytes

Versions: 8

Compression:

Stored size: 438 Bytes

Contents

# frozen_string_literal: true

class Shaped::Shapes::Callable < Shaped::Shape
  def initialize(callable)
    @callable = callable
  end

  def matched_by?(object)
    !!@callable.call(object)
  end

  def to_s
    case @callable
    when Proc then "Proc test defined at #{@callable.source_location.map(&:to_s).join(':')}"
    else "#call test defined at #{@callable.method(:call).source_location.map(&:to_s).join(':')}"
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
shaped-0.7.3 lib/shaped/shapes/callable.rb
shaped-0.7.2 lib/shaped/shapes/callable.rb
shaped-0.7.1 lib/shaped/shapes/callable.rb
shaped-0.7.0 lib/shaped/shapes/callable.rb
shaped-0.6.4 lib/shaped/shapes/callable.rb
shaped-0.6.3 lib/shaped/shapes/callable.rb
shaped-0.6.2 lib/shaped/shapes/callable.rb
shaped-0.6.1 lib/shaped/shapes/callable.rb