Class: NxtSchema::Callable
- Inherits:
-
Object
- Object
- NxtSchema::Callable
- Defined in:
- lib/nxt_schema/callable.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(callable, target = nil, *args) ⇒ Callable
constructor
A new instance of Callable.
- #method? ⇒ Boolean
- #proc? ⇒ Boolean
- #value? ⇒ Boolean
Constructor Details
#initialize(callable, target = nil, *args) ⇒ Callable
Returns a new instance of Callable.
3 4 5 6 7 |
# File 'lib/nxt_schema/callable.rb', line 3 def initialize(callable, target = nil, *args) @callable = callable @target = target @args = args end |
Instance Method Details
#call ⇒ Object
9 10 11 12 13 14 |
# 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? ⇒ Boolean
16 17 18 |
# File 'lib/nxt_schema/callable.rb', line 16 def method? @method ||= callable.class.in?([Symbol, String]) && target.respond_to?(callable) end |
#proc? ⇒ Boolean
20 21 22 |
# File 'lib/nxt_schema/callable.rb', line 20 def proc? @proc ||= callable.respond_to?(:call) end |
#value? ⇒ Boolean
24 25 26 |
# File 'lib/nxt_schema/callable.rb', line 24 def value? !method? && !proc? end |