Permalink
Browse files

Small usage improvements

  • Loading branch information...
1 parent 0ba37c6 commit 8216086ece42a7acae70cacb9acba73cbe405670 @meh committed Sep 1, 2011
Showing with 8 additions and 3 deletions.
  1. +7 −2 lib/with.rb
  2. +1 −1 lib/with/io.rb
View
@@ -26,9 +26,14 @@ def with (*objects, &block)
exception = e
end
-
raise exception if objects.none? {|object|
- object.respond_to?(:__exit__) && object.__exit__(exception)
+ next unless object.respond_to?(:__exit__)
+
+ if object.method(:__exit__).arity == 0
+ object.__exit__ && false
+ else
+ object.__exit__(exception)
+ end
} && exception
result
View
@@ -11,7 +11,7 @@
#++
class IO
- def __exit__ (*)
+ def __exit__
close rescue nil
end
end

0 comments on commit 8216086

Please sign in to comment.