Class: Shaped::Shapes::Callable

Inherits:
Shaped::Shape show all
Defined in:
lib/shaped/shapes/callable.rb

Instance Method Summary collapse

Constructor Details

#initialize(callable) ⇒ Callable

Returns a new instance of Callable.



4
5
6
# File 'lib/shaped/shapes/callable.rb', line 4

def initialize(callable)
  @callable = callable
end

Instance Method Details

#matched_by?(object) ⇒ Boolean

Returns:



8
9
10
# File 'lib/shaped/shapes/callable.rb', line 8

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

#to_sObject



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/shaped/shapes/callable.rb', line 12

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