Class: Multiblock::Wrapper
- Inherits:
-
BasicObject
- Defined in:
- lib/multiblock/wrapper.rb
Instance Method Summary
collapse
Constructor Details
#initialize(&default) ⇒ Wrapper
Returns a new instance of Wrapper.
3
4
5
6
7
|
# File 'lib/multiblock/wrapper.rb', line 3
def initialize(&default)
default ||= ::Kernel.lambda { |*args| nil }
@blocks = ::Hash.new(default)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &blk) ⇒ Object
9
10
11
12
|
# File 'lib/multiblock/wrapper.rb', line 9
def method_missing(name, *args, &blk)
::Kernel.raise ::ArgumentError.new("No block given when registering '#{name}' block.") if blk.nil?
@blocks[name.to_s] = blk
end
|
Instance Method Details
#call(name, *args) ⇒ Object
14
15
16
|
# File 'lib/multiblock/wrapper.rb', line 14
def call(name, *args)
@blocks[name.to_s].call(*args)
end
|
#inspect ⇒ Object
18
19
20
|
# File 'lib/multiblock/wrapper.rb', line 18
def inspect
"#<Multiblock::Wrapper @blocks=#{@blocks.inspect}>"
end
|