Top Level Namespace
Defined Under Namespace
Classes: CallWith
Instance Method Summary collapse
-
#callwith(*objs, &block) ⇒ Object
Iterate over the given objects and delegate all instance method calls in the block to the object.
Instance Method Details
#callwith(*objs, &block) ⇒ Object
Iterate over the given objects and delegate all instance method calls in the block to the object. Instance variables accessed from inside the block are delegated to the receiver of the method. Returns the result of the last expression evaluated.
Example:
callwith(file1, file2) do
write("this is a test")
end
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/callwith.rb', line 14 def callwith(*objs, &block) last = nil objs.each do |obj| p = CallWith.create(obj, self) begin last = p.__instance_eval__(&block) ensure p.__callwith__cleanup__() end end return last end |