class Fear::PartialFunctionClass
@api private
Attributes
condition[R]
function[R]
Public Class Methods
new(condition, &function)
click to toggle source
@param condition [#call] describes the domain of partial function @param function [Proc] function definition
# File lib/fear/partial_function_class.rb, line 10 def initialize(condition, &function) @condition = condition @function = function end
Public Instance Methods
call(arg)
click to toggle source
@param arg [any] @return [any] Calls this partial function with the given argument when it
is contained in the function domain.
@raise [MatchError] when this partial function is not defined.
# File lib/fear/partial_function_class.rb, line 22 def call(arg) call_or_else(arg, &PartialFunction::EMPTY) end
call_or_else(arg) { |arg| ... }
click to toggle source
@param arg [any] @yield [arg] if function not defined
# File lib/fear/partial_function_class.rb, line 28 def call_or_else(arg) if defined_at?(arg) function.(arg) else yield arg end end