Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Small usage improvements

  • Loading branch information...
commit 8216086ece42a7acae70cacb9acba73cbe405670 1 parent 0ba37c6
meh. authored

Showing 2 changed files with 8 additions and 3 deletions. Show diff stats Hide diff stats

  1. +7 2 lib/with.rb
  2. +1 1  lib/with/io.rb
9 lib/with.rb
@@ -26,9 +26,14 @@ def with (*objects, &block)
26 26 exception = e
27 27 end
28 28
29   -
30 29 raise exception if objects.none? {|object|
31   - object.respond_to?(:__exit__) && object.__exit__(exception)
  30 + next unless object.respond_to?(:__exit__)
  31 +
  32 + if object.method(:__exit__).arity == 0
  33 + object.__exit__ && false
  34 + else
  35 + object.__exit__(exception)
  36 + end
32 37 } && exception
33 38
34 39 result
2  lib/with/io.rb
@@ -11,7 +11,7 @@
11 11 #++
12 12
13 13 class IO
14   - def __exit__ (*)
  14 + def __exit__
15 15 close rescue nil
16 16 end
17 17 end

0 comments on commit 8216086

Please sign in to comment.
Something went wrong with that request. Please try again.