Created
March 24, 2011 16:00
-
-
Save pivotal-casebook/885305 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Processes a given +block+. Yields objects if the block expects any arguments. | |
# Otherwise evaluates the block in the context of this object. | |
def process(offset = 0, &block) | |
block.arity > 0 ? yield_objects(offset, &block) : evaluate(&block) | |
end | |
# Yields a number of objects to a given +block+ depending on how many arguments | |
# the block is expecting. | |
def yield_objects(offset, &block) | |
yield *[soap, wsdl, http, wsse][offset, block.arity] | |
end | |
# Evaluates a given +block+ inside this object. Stores the original block binding. | |
def evaluate(&block) | |
self.original_self = eval "self", block.binding | |
instance_eval &block | |
end | |
# Handles calls to undefined methods by delegating to the original block binding. | |
def method_missing(method, *args, &block) | |
super unless original_self | |
original_self.send method, *args, &block | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment