with 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/with.rb +30 -24
- data/lib/with/io.rb +3 -3
- metadata +11 -14
data/lib/with.rb
CHANGED
@@ -11,31 +11,37 @@
|
|
11
11
|
#++
|
12
12
|
|
13
13
|
module Kernel
|
14
|
-
|
15
|
-
|
14
|
+
def with (*objects, &block)
|
15
|
+
result, exception = nil
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
17
|
+
begin
|
18
|
+
result = block.call *objects.map {|object|
|
19
|
+
if object.respond_to? :__enter__
|
20
|
+
object.__enter__
|
21
|
+
else
|
22
|
+
object
|
23
|
+
end
|
24
|
+
}
|
25
|
+
rescue Exception => e
|
26
|
+
exception = e
|
27
|
+
end
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
if object.method(:__exit__).arity == 0
|
33
|
-
object.__exit__ && false
|
34
|
-
else
|
35
|
-
object.__exit__(exception)
|
36
|
-
end
|
37
|
-
} && exception
|
29
|
+
raise exception if objects.none? {|object|
|
30
|
+
next unless object.respond_to?(:__exit__)
|
38
31
|
|
39
|
-
|
40
|
-
|
32
|
+
if object.method(:__exit__).arity == 0
|
33
|
+
object.__exit__ && false
|
34
|
+
else
|
35
|
+
object.__exit__(exception)
|
36
|
+
end
|
37
|
+
} && exception
|
38
|
+
|
39
|
+
result
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class Object
|
44
|
+
def tap! (&block)
|
45
|
+
Kernel.with(self, &block)
|
46
|
+
end
|
41
47
|
end
|
data/lib/with/io.rb
CHANGED
metadata
CHANGED
@@ -1,18 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: with
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
4
|
+
version: 0.0.5
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- meh.
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
13
|
-
default_executable:
|
12
|
+
date: 2011-10-10 00:00:00.000000000 Z
|
14
13
|
dependencies: []
|
15
|
-
description:
|
14
|
+
description:
|
16
15
|
email: meh@paranoici.org
|
17
16
|
executables: []
|
18
17
|
extensions: []
|
@@ -21,30 +20,28 @@ files:
|
|
21
20
|
- lib/with.rb
|
22
21
|
- lib/with/io.rb
|
23
22
|
- lib/with/adapters.rb
|
24
|
-
has_rdoc: true
|
25
23
|
homepage: http://github.com/meh/ruby-with
|
26
24
|
licenses: []
|
27
|
-
post_install_message:
|
25
|
+
post_install_message:
|
28
26
|
rdoc_options: []
|
29
27
|
require_paths:
|
30
28
|
- lib
|
31
29
|
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
32
31
|
requirements:
|
33
32
|
- - ! '>='
|
34
33
|
- !ruby/object:Gem::Version
|
35
34
|
version: '0'
|
36
|
-
none: false
|
37
35
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
38
37
|
requirements:
|
39
38
|
- - ! '>='
|
40
39
|
- !ruby/object:Gem::Version
|
41
40
|
version: '0'
|
42
|
-
none: false
|
43
41
|
requirements: []
|
44
|
-
rubyforge_project:
|
45
|
-
rubygems_version: 1.
|
46
|
-
signing_key:
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 1.8.10
|
44
|
+
signing_key:
|
47
45
|
specification_version: 3
|
48
46
|
summary: Stupid Python-like with statement
|
49
47
|
test_files: []
|
50
|
-
...
|