Sha256: 3a996f14f0e74ed2c3e8d43cf8bbe76892fc217d8563553ed06b4d302a14d53c

Contents?: true

Size: 530 Bytes

Versions: 6

Compression:

Stored size: 530 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 Method then "Method defined at #{@callable.source_location.map(&:to_s).join(':')}"
    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

6 entries across 6 versions & 1 rubygems

Version Path
shaped-0.11.0 lib/shaped/shapes/callable.rb
shaped-0.10.0 lib/shaped/shapes/callable.rb
shaped-0.9.1 lib/shaped/shapes/callable.rb
shaped-0.9.0 lib/shaped/shapes/callable.rb
shaped-0.8.2 lib/shaped/shapes/callable.rb
shaped-0.8.0 lib/shaped/shapes/callable.rb