Class: Shaped::Shapes::Callable
- Inherits:
-
Shaped::Shape
- Object
- Shaped::Shape
- Shaped::Shapes::Callable
- Defined in:
- lib/shaped/shapes/callable.rb
Instance Method Summary collapse
-
#initialize(callable) ⇒ Callable
constructor
A new instance of Callable.
- #matched_by?(object) ⇒ Boolean
- #to_s ⇒ Object
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
8 9 10 |
# File 'lib/shaped/shapes/callable.rb', line 8 def matched_by?(object) !!@callable.call(object) end |
#to_s ⇒ Object
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 |