try-catch 1.4.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +12 -10
- data/VERSION +1 -1
- data/examples/try_catch.rb +2 -2
- data/examples/try_return_nil.rb +3 -3
- data/lib/try-catch/syntax.rb +9 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3116ca00b9fb6c66331b31bfebe24e52e4e3f62
|
4
|
+
data.tar.gz: 8f00de890b712aa1d5417ff3e10ebc4d3d197f8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47ce00ae6d583df3a5d68698eb3d266cd5fe82c5d771c5d8d52f2840810b71abdf7d2fb5305b51aa3a2f6ed377c8e736f13d5e81c543955e6787ad7eebcacedb
|
7
|
+
data.tar.gz: 49886b0a034f7668be4782dfeb92b0011dc95b7b3f70b72e1ff75535266e3caa16924497f7369ebb6123a2ecfdfd235f0ec66e2790dec025e0f9e4d55d571343
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -13,19 +13,21 @@ if you new to ruby and missing the try catch block here is a simple one for you
|
|
13
13
|
|
14
14
|
require 'try-catch'
|
15
15
|
|
16
|
-
|
16
|
+
__try__ { hello world }.catch{ "not hello world " }
|
17
17
|
#> "not hello world"
|
18
18
|
|
19
|
-
|
19
|
+
__try__ { "hello world".asdaf }.catch( NoMethodError ) { |ex| "there is and error, because #{ex}" }
|
20
20
|
#> there is and error, because undefined method `asdaf' for "hello world":String
|
21
21
|
|
22
22
|
#> you can cain up multiple catch for specific error
|
23
|
-
|
23
|
+
__try__ { "hello world".asdaf }.catch( NoMethodError ) { |ex| "there is and error, because #{ex}" }
|
24
24
|
|
25
|
-
puts
|
25
|
+
puts __try__ { "hello world".asdaf }.catch(ArgumentError) { "it was and argument error" }.catch( NoMethodError ) { |ex| "bla bla #{ex}" }
|
26
26
|
#> "bla bla undefined method `asdaf' for "hello world":String"
|
27
27
|
|
28
|
-
puts
|
28
|
+
puts __try_nc__ { "hello world".asd } #> non cached try block
|
29
|
+
|
30
|
+
puts __try_n__ { "hello".asd } || __try_n__{ "hello".downcase } #> "hello"
|
29
31
|
|
30
32
|
```
|
31
33
|
|
@@ -33,8 +35,8 @@ if you new to ruby and missing the try catch block here is a simple one for you
|
|
33
35
|
|
34
36
|
```ruby
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
+
__try__ { puts "hello world".asdf }
|
39
|
+
__catch__ { |ex| puts ex.to_s.upcase }
|
38
40
|
#> UNDEFINED METHOD `ASDF' FOR "HELLO WORLD":STRING
|
39
41
|
|
40
42
|
```
|
@@ -43,9 +45,9 @@ or in each line version with specific Exception case
|
|
43
45
|
|
44
46
|
```ruby
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
-
|
48
|
+
__try__ { puts "hello world".asdf }
|
49
|
+
__catch__(ArgumentError) { |ex| puts ex.to_s.capitalize }
|
50
|
+
__catch__(NoMethodError) { |ex| puts ex.to_s.upcase }
|
49
51
|
|
50
52
|
```
|
51
53
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
2.0.0
|
data/examples/try_catch.rb
CHANGED
data/examples/try_return_nil.rb
CHANGED
@@ -16,6 +16,7 @@ module TestA
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
+
|
19
20
|
module TestB
|
20
21
|
class << self
|
21
22
|
|
@@ -35,10 +36,9 @@ module TestC
|
|
35
36
|
class << self
|
36
37
|
|
37
38
|
def method_missing method_name, *args
|
38
|
-
return
|
39
|
+
return __try_nil__{ ::TestA.__send__(method_name,*args) } || __try_nil__{ ::TestB.__send__(method_name,*args) }
|
39
40
|
end
|
40
41
|
|
41
|
-
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -52,4 +52,4 @@ hello world
|
|
52
52
|
complex
|
53
53
|
complex: sup!
|
54
54
|
|
55
|
-
=
|
55
|
+
=end
|
data/lib/try-catch/syntax.rb
CHANGED
@@ -3,21 +3,24 @@ module TryCatch
|
|
3
3
|
EXT= Module.new
|
4
4
|
module EXT::Object
|
5
5
|
|
6
|
-
|
6
|
+
#> return ex and cache
|
7
|
+
def __try__ *exception_classes, &block
|
7
8
|
::TryCatch::Function.try( self, *exception_classes, &block )
|
8
9
|
end
|
9
10
|
|
10
|
-
|
11
|
+
#> return ex but not cache
|
12
|
+
def __try_nc__ *exception_classes, &block
|
11
13
|
::TryCatch::Function.try_no_cache( *exception_classes, &block )
|
12
14
|
end
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
def try? *exception_classes, &block
|
16
|
+
#> return nil if fail
|
17
|
+
def __try_nil__ *exception_classes, &block
|
17
18
|
::TryCatch::Function.try?( *exception_classes, &block )
|
18
19
|
end
|
20
|
+
alias __try_n__ __try_nil__
|
19
21
|
|
20
|
-
|
22
|
+
#> catch from cach or on self obj
|
23
|
+
def __catch__ *exception_classes, &block
|
21
24
|
::TryCatch::Function.catch self, *exception_classes, &block
|
22
25
|
end
|
23
26
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: try-catch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Luzsi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|