Class: Liquidscript::Compiler::Base::Callable
- Inherits:
-
Object
- Object
- Liquidscript::Compiler::Base::Callable
- Defined in:
- lib/liquidscript/compiler/base/callable.rb
Instance Method Summary collapse
-
#arity ⇒ Numeric
How many arguments the call can take.
-
#call(*args) ⇒ Object
Calls the thing that this represents.
-
#initialize(bind, block) ⇒ Callable
constructor
Initialize the callable.
Constructor Details
#initialize(bind, block) ⇒ Callable
Initialize the callable.
12 13 14 15 16 17 18 19 |
# File 'lib/liquidscript/compiler/base/callable.rb', line 12 def initialize(bind, block) @bind = bind @block = if block.is_a? Symbol :"compile_#{block}" else block end end |
Instance Method Details
#arity ⇒ Numeric
How many arguments the call can take. If this represents a block that has tricks enabled, then this isn’t an issue; if it’s a method call, however, it becomes important.
40 41 42 43 44 45 46 |
# File 'lib/liquidscript/compiler/base/callable.rb', line 40 def arity if @block.is_a? Symbol @bind.method(@block).arity else @block.arity end end |
#call(*args) ⇒ Object
Calls the thing that this represents. If this represents a method call, it calls the method with the given arguments; otherwise, it calls #call on the block.
27 28 29 30 31 32 33 |
# File 'lib/liquidscript/compiler/base/callable.rb', line 27 def call(*args) if @block.is_a? Symbol @bind.public_send(@block, *args) elsif @block.respond_to?(:call) @block.call(*args) end end |