with 0.0.1

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.
Files changed (2) hide show
  1. data/lib/with.rb +41 -0
  2. metadata +54 -0
data/lib/with.rb ADDED
@@ -0,0 +1,41 @@
1
+ #--
2
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3
+ # Version 2, December 2004
4
+ #
5
+ # Copyleft meh. [http://meh.paranoid.pk | meh@paranoici.org]
6
+ #
7
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
8
+ # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
9
+ #
10
+ # 0. You just DO WHAT THE FUCK YOU WANT TO.
11
+ #++
12
+
13
+ module Kernel
14
+ def with (*objects, &block)
15
+ result, exception = nil
16
+
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
+
29
+ if objects.length == 1
30
+ if objects.first.respond_to? :__exit__
31
+ objects.first.__exit__ exception
32
+ else
33
+ raise exception if exception
34
+ end
35
+ else
36
+ raise exception if exception
37
+ end
38
+
39
+ result
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: with
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - meh.
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-08-27 00:00:00 Z
14
+ dependencies: []
15
+
16
+ description:
17
+ email: meh@paranoici.org
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/with.rb
26
+ homepage: http://github.com/meh/ruby-with
27
+ licenses: []
28
+
29
+ post_install_message:
30
+ rdoc_options: []
31
+
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: "0"
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ requirements: []
47
+
48
+ rubyforge_project:
49
+ rubygems_version: 1.8.5
50
+ signing_key:
51
+ specification_version: 3
52
+ summary: Stupid Python-like with statement
53
+ test_files: []
54
+