Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Small usage improvements

  • Loading branch information...
commit 8216086ece42a7acae70cacb9acba73cbe405670 1 parent 0ba37c6
@meh authored
Showing with 8 additions and 3 deletions.
  1. +7 −2 lib/with.rb
  2. +1 −1  lib/with/io.rb
View
9 lib/with.rb
@@ -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
2  lib/with/io.rb
@@ -11,7 +11,7 @@
#++
class IO
- def __exit__ (*)
+ def __exit__
close rescue nil
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.