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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6a929e2dd08580f5df4943cc4e4c4ea2f9badaf1
4
- data.tar.gz: c1d56de1a61958d47614b845fa8097a7778da03b
3
+ metadata.gz: f3116ca00b9fb6c66331b31bfebe24e52e4e3f62
4
+ data.tar.gz: 8f00de890b712aa1d5417ff3e10ebc4d3d197f8c
5
5
  SHA512:
6
- metadata.gz: 07dea44d045e46e182636eab8817c15514ae670b90801b921ad1acd81a75eb9a3825ad6ac0501ed4738b4fbe1b0523740def18fb182163b99dbc5b0e72dbfc65
7
- data.tar.gz: ea8e64484f6cb46153da2b84f403d8c088056e3a35e6b98137ccb3f1966ecabb27e0ac064f08174c08818be6817c9af36da70e1dc123a41985aafa5d0aa26b11
6
+ metadata.gz: 47ce00ae6d583df3a5d68698eb3d266cd5fe82c5d771c5d8d52f2840810b71abdf7d2fb5305b51aa3a2f6ed377c8e736f13d5e81c543955e6787ad7eebcacedb
7
+ data.tar.gz: 49886b0a034f7668be4782dfeb92b0011dc95b7b3f70b72e1ff75535266e3caa16924497f7369ebb6123a2ecfdfd235f0ec66e2790dec025e0f9e4d55d571343
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- try-catch (1.4.0)
4
+ try-catch (2.0.0)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
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
- try { hello world }.catch{ "not hello world " }
16
+ __try__ { hello world }.catch{ "not hello world " }
17
17
  #> "not hello world"
18
18
 
19
- try { "hello world".asdaf }.catch( NoMethodError ) { |ex| "there is and error, because #{ex}" }
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
- try { "hello world".asdaf }.catch( NoMethodError ) { |ex| "there is and error, because #{ex}" }
23
+ __try__ { "hello world".asdaf }.catch( NoMethodError ) { |ex| "there is and error, because #{ex}" }
24
24
 
25
- puts try { "hello world".asdaf }.catch(ArgumentError) { "it was and argument error" }.catch( NoMethodError ) { |ex| "bla bla #{ex}" }
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 try_nc { "hello world".asd } #> non cached try block
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
- try { puts "hello world".asdf }
37
- catch { |ex| puts ex.to_s.upcase }
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
- try { puts "hello world".asdf }
47
- catch(ArgumentError) { |ex| puts ex.to_s.capitalize }
48
- catch(NoMethodError) { |ex| puts ex.to_s.upcase }
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.4.0
1
+ 2.0.0
@@ -4,5 +4,5 @@ require_relative '../lib/try-catch/syntax'
4
4
 
5
5
  require 'debugger'
6
6
 
7
- try { puts("hello world".z) }
8
- catch(NoMethodError) { |ex| puts ex.to_s.upcase }
7
+ __try__ { puts("hello world".z) }
8
+ __catch__(NoMethodError) { |ex| puts ex.to_s.upcase }
@@ -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 try?{ ::TestA.__send__(method_name,*args) } || try?{ ::TestB.__send__(method_name,*args) }
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
- =begin
55
+ =end
@@ -3,21 +3,24 @@ module TryCatch
3
3
  EXT= Module.new
4
4
  module EXT::Object
5
5
 
6
- def try *exception_classes, &block
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
- def try_nc *exception_classes, &block
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
- alias :try_no_cache :try_nc
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
- def catch *exception_classes, &block
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: 1.4.0
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-05 00:00:00.000000000 Z
11
+ date: 2014-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake