try 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/try.rb +19 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 709e480aa70f8f56410a63ec46009b96803e116b
|
4
|
+
data.tar.gz: b16217ce61a1bdc4eb589e632297ac4a29d414ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4225e05e4cbf52002cfc805cf6ad792366a748d0ca627f72b6cd49a41324ab371146d553f783d4cc80a23bc45de60487f7cc2e3336b1aee4861e3dc62def597
|
7
|
+
data.tar.gz: c3d7923acfc692c72dde29c0e250d1b9f5eb838530c2a23783ebc10e9286a66c5e42d72614f30d3b95a0e6c813853b145b04eb13cf81b3e233290b843c37da43
|
data/lib/try.rb
CHANGED
@@ -38,6 +38,25 @@ module Try
|
|
38
38
|
raise
|
39
39
|
end
|
40
40
|
|
41
|
+
#
|
42
|
+
# Evaluates the given block and returns its value.
|
43
|
+
# If an exception is raised, nil is returned instead.
|
44
|
+
#
|
45
|
+
# If ((%errs%)) are given, only those exceptions will be trapped,
|
46
|
+
# and any other exceptions will be raised normally.
|
47
|
+
#
|
48
|
+
# @param errs an optional list of exception types to trap.
|
49
|
+
#
|
50
|
+
def test *errs, &bk
|
51
|
+
yield
|
52
|
+
rescue Exception => ex
|
53
|
+
return nil if errs.empty?
|
54
|
+
errs.each do |klass|
|
55
|
+
return nil if klass.instance_of?(Module) ? ex.kind_of?(klass) : ex.is_a?(klass)
|
56
|
+
end
|
57
|
+
raise
|
58
|
+
end
|
59
|
+
|
41
60
|
extend self
|
42
61
|
end
|
43
62
|
|