Skip to content

Instantly share code, notes, and snippets.

@pivotal-casebook
Created March 24, 2011 16:00
Show Gist options
  • Save pivotal-casebook/885305 to your computer and use it in GitHub Desktop.
Save pivotal-casebook/885305 to your computer and use it in GitHub Desktop.
# 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