BlockCapture is designed with a couple ideas in mind.
- It should be able to capture multiple blocks.
- You're program should be able to specify the types of blocks it wants to receive and have the ability to call them at the appropriate time.
- When a user specifies a block that the library author has not specified, they are notified of their error.
BlockCapture
is an interface for the user of the library and the implementor of the library and should have error messaging to reflect those two situations. (block_given? error vs non-block_given? error)- Blocks can be optionally provided, so you should be able to check if a block has been provided.
method_missing
andcapture
are the only methods defined to not limit the names for methods the library author can use for capturing blocks.BlockCapture
has state and behavior, and thus should be encapsulated as an object rather than as a module to be mixed in.
I'm not sure this can be used generically very easily, it looks like you need a non-trivial custom class per method that accepts multiple blocks.