class NxtSchema::Callable
Attributes
args[R]
callable[R]
target[R]
Public Class Methods
new(callable, target = nil, *args)
click to toggle source
# File lib/nxt_schema/callable.rb, line 3 def initialize(callable, target = nil, *args) @callable = callable @target = target @args = args end
Public Instance Methods
call()
click to toggle source
# File lib/nxt_schema/callable.rb, line 9 def call return callable if value? return callable.call(*args_from_arity) if proc? target.send(callable, *args_from_arity) end
method?()
click to toggle source
# File lib/nxt_schema/callable.rb, line 16 def method? @method ||= callable.class.in?([Symbol, String]) && target.respond_to?(callable) end
proc?()
click to toggle source
# File lib/nxt_schema/callable.rb, line 20 def proc? @proc ||= callable.respond_to?(:call) end
value?()
click to toggle source
# File lib/nxt_schema/callable.rb, line 24 def value? !method? && !proc? end
Private Instance Methods
args_from_arity()
click to toggle source
# File lib/nxt_schema/callable.rb, line 36 def args_from_arity @args_from_arity ||= ([target] + args).take(arity) end
arity()
click to toggle source
# File lib/nxt_schema/callable.rb, line 32 def arity proc? ? callable.arity : 0 end