cc 1.1.0
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.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/LICENSE-CN.md +9 -0
- data/README.md +3 -0
- data/attribute.rb +71 -0
- data/cc.rb +43 -0
- data/chinese.rb +71 -0
- data/chrono.rb +162 -0
- data/enum.rb +47 -0
- data/exception.rb +91 -0
- data/file.rb +253 -0
- data/kernel.rb +227 -0
- data/monkey-patch.rb +116 -0
- data/number.rb +105 -0
- data/regexp.rb +23 -0
- data/string.rb +75 -0
- data/tree.rb +184 -0
- metadata +57 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3845aa1ea0a757e0457a34c7a5262a492f0f172b07f143cb5bb01f2e025dcfd2
|
4
|
+
data.tar.gz: '01603958c108049cdd77b01399ceb6d1ebdf927187b005455fa15cb106df79e9'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 15268def1cc4604f43c243fca0cb66744e64cd186d7679107aab2e7363fe85990c2c1ef6363dc567241943fdb3d730ceff405a3b56c32a1c9e8e51ced79c3f74
|
7
|
+
data.tar.gz: 338fd1f52a6eed257b3079e6d06b11a471d1cbaa5e326e433fc063e3b8108d65adb10c7b4f64537630c979178878983a4c84b2c2623e3a5280ff1df1d4e4cb35
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 Frampt
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/LICENSE-CN.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
MIT 许可证
|
2
|
+
|
3
|
+
版权所有 (c) 2025 Frampt
|
4
|
+
|
5
|
+
特此授予获得本软件及其相关文档文件(以下简称“软件”)副本的任何人,免费使用本软件的权利,包括但不限于使用、复制、修改、合并、发布、分发、再授权以及出售软件副本的权利,并允许接收本软件的人员也这样做,但需满足以下条件:
|
6
|
+
|
7
|
+
上述版权声明和本许可声明必须包含在软件的所有副本或重要部分中。
|
8
|
+
|
9
|
+
软件“按原样”提供,没有任何形式的保证,无论是明示还是暗示,包括但不限于对适销性、特定用途的适用性和非侵权性的保证。在任何情况下,作者或版权持有人都不对任何索赔、损害或其他责任负责,无论是在合同、侵权行为或其他行为中,因使用、履行或与软件相关的其他交易而产生。
|
data/README.md
ADDED
data/attribute.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
#coding:utf-8
|
2
|
+
|
3
|
+
############################################################################################################
|
4
|
+
# HOW TO USE #
|
5
|
+
############################################################################################################
|
6
|
+
|
7
|
+
=begin
|
8
|
+
require 'cc'
|
9
|
+
CC.use 'attribute'
|
10
|
+
|
11
|
+
# use Attribute module with obj[xxx]
|
12
|
+
class Sample
|
13
|
+
include Attribute
|
14
|
+
end
|
15
|
+
s1 = Sample.new
|
16
|
+
|
17
|
+
s1['name'], s1[:age] = "sample", 100
|
18
|
+
p s1[:name], s1['age'], s1.attrs
|
19
|
+
|
20
|
+
# use Component module with obj.xxx
|
21
|
+
s2 = Object.new
|
22
|
+
s2.extend Component
|
23
|
+
|
24
|
+
s2.link 'name' => 'sample', age: 100
|
25
|
+
p s2.name, s2.age, s2.coms
|
26
|
+
=end
|
27
|
+
|
28
|
+
module Attribute
|
29
|
+
def attrs
|
30
|
+
@attrs ||= Hash.new
|
31
|
+
end
|
32
|
+
|
33
|
+
def [] name
|
34
|
+
@attrs ||= Hash.new
|
35
|
+
return @attrs[name.to_sym]
|
36
|
+
end
|
37
|
+
|
38
|
+
def []= name,value
|
39
|
+
@attrs ||= Hash.new
|
40
|
+
return @attrs[name.to_sym] = value
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
module Component
|
45
|
+
def coms
|
46
|
+
@attrs ||= Hash.new
|
47
|
+
end
|
48
|
+
|
49
|
+
def method_missing name,*args
|
50
|
+
@attrs ||= Hash.new
|
51
|
+
return @attrs[name.to_sym]
|
52
|
+
end
|
53
|
+
|
54
|
+
def [] name
|
55
|
+
@attrs ||= Hash.new
|
56
|
+
@attrs[name.to_sym]
|
57
|
+
end
|
58
|
+
|
59
|
+
def []= name,entity
|
60
|
+
@attrs[name.to_sym] = entity
|
61
|
+
end
|
62
|
+
|
63
|
+
def link pairs
|
64
|
+
@attrs ||= Hash.new
|
65
|
+
if pairs.class == Hash
|
66
|
+
pairs.each{|k,v| @attrs.merge! k.to_sym=>v }
|
67
|
+
else
|
68
|
+
@attrs.merge! pairs.class.to_sym=>pairs
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/cc.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
#coding:utf-8
|
2
|
+
|
3
|
+
$modlist = [
|
4
|
+
'cc',
|
5
|
+
'attribute',
|
6
|
+
'chinese',
|
7
|
+
'chrono',
|
8
|
+
'enum',
|
9
|
+
'exception',
|
10
|
+
'file',
|
11
|
+
'kernel',
|
12
|
+
'monkey-patch',
|
13
|
+
'number',
|
14
|
+
'regexp',
|
15
|
+
'string',
|
16
|
+
'tree'
|
17
|
+
]
|
18
|
+
|
19
|
+
module CC
|
20
|
+
module_function
|
21
|
+
|
22
|
+
def list *names
|
23
|
+
$modlist.each do|mod|
|
24
|
+
puts mod if names.include?(mod) || names.empty?
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def select *args
|
29
|
+
if args.include?(:all)
|
30
|
+
$modlist.each do|mod|
|
31
|
+
load(mod+'.rb')
|
32
|
+
end
|
33
|
+
else
|
34
|
+
args.each do|arg|
|
35
|
+
load(arg+'.rb') if $modlist.include?(arg)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def use *args
|
41
|
+
select(*args)
|
42
|
+
end
|
43
|
+
end
|
data/chinese.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
#coding:utf-8
|
2
|
+
|
3
|
+
############################################################################################################
|
4
|
+
# HOW TO USE #
|
5
|
+
############################################################################################################
|
6
|
+
|
7
|
+
=begin
|
8
|
+
require 'cc'
|
9
|
+
CC.use 'chinese' # immediately when loading this file
|
10
|
+
=end
|
11
|
+
|
12
|
+
class Object
|
13
|
+
def 等于(对象);(self.equal? 对象);end
|
14
|
+
def 等于?(对象);(self.equal? 对象);end
|
15
|
+
def 等于?(对象);(self.equal? 对象);end
|
16
|
+
def 不等于(对象);!(self.equal? 对象);end
|
17
|
+
def 不等于?(对象);!(self.equal? 对象);end
|
18
|
+
def 不等于?(对象);!(self.equal? 对象);end
|
19
|
+
def 包含(对象);self.include?(对象);end # 如果重写,覆盖本方法
|
20
|
+
def 包含?(对象);self.include?(对象);end
|
21
|
+
def 包含?(对象);self.include?(对象);end
|
22
|
+
def 属于(对象);对象.include?(对象);end # 如果重写,覆盖本方法
|
23
|
+
def 属于?(对象);对象.include?(对象);end
|
24
|
+
def 属于?(对象);对象.include?(对象);end
|
25
|
+
end
|
26
|
+
|
27
|
+
class Numeric
|
28
|
+
def 大于(对象);self>对象;end
|
29
|
+
def 大于?(对象);self>对象;end
|
30
|
+
def 大于?(对象);self>对象;end
|
31
|
+
def 大于等于(对象);self>=对象;end
|
32
|
+
def 大于等于?(对象);self>=对象;end
|
33
|
+
def 大于等于?(对象);self>=对象;end
|
34
|
+
def 小于(对象);self<对象;end
|
35
|
+
def 小于?(对象);self<对象;end
|
36
|
+
def 小于?(对象);self<对象;end
|
37
|
+
def 小于等于(对象);self<=对象;end
|
38
|
+
def 小于等于?(对象);self<=对象;end
|
39
|
+
def 小于等于?(对象);self<=对象;end
|
40
|
+
# 等于/不等于 in Object
|
41
|
+
|
42
|
+
["时","分","秒"].each do|单位|
|
43
|
+
define_method 单位.to_sym do
|
44
|
+
return self
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
module Enumerable
|
50
|
+
def 包含? 其他;self.include?(其他);end # rewrite object
|
51
|
+
def 包含? 其他;self.include?(其他);end # rewrite object
|
52
|
+
end
|
53
|
+
|
54
|
+
module Kernel
|
55
|
+
def 打印 *参数
|
56
|
+
send :puts,*参数
|
57
|
+
end
|
58
|
+
|
59
|
+
def 内视 *参数
|
60
|
+
send :p,*参数
|
61
|
+
end
|
62
|
+
|
63
|
+
def 内视图 *参数
|
64
|
+
# require 'pp' # v2.5.0 build-in, no need require when v3.0.0+
|
65
|
+
send :pp,*参数
|
66
|
+
end
|
67
|
+
|
68
|
+
def 休眠 时间
|
69
|
+
sleep 时间
|
70
|
+
end
|
71
|
+
end
|
data/chrono.rb
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
#coding:utf-8
|
2
|
+
require 'date'
|
3
|
+
require 'time'
|
4
|
+
|
5
|
+
############################################################################################################
|
6
|
+
# HOW TO USE #
|
7
|
+
############################################################################################################
|
8
|
+
|
9
|
+
=begin
|
10
|
+
require 'cc'
|
11
|
+
CC.use 'chrono' # immediately when loading this file
|
12
|
+
|
13
|
+
timing = Time.now
|
14
|
+
puts [2023, 10, 10, 12, 30, 45]=="2023-10-10 12:30:45".time,
|
15
|
+
[2023, 10, 10, 12, 30, 45]=="2023-10-10T12:30:45".time,
|
16
|
+
[timing.year, timing.month, timing.day, timing.hour, timing.min, timing.sec]==(Time.now).strftime("%Y-%m-%d %H:%M:%S").time,
|
17
|
+
["12", "30", "45"]=="123045".tag_to_numtime,
|
18
|
+
"12:30:45"=="123045".tag_to_time,
|
19
|
+
["2023", "10", "10"]=="20231010".tag_to_numdate,
|
20
|
+
"2023-10-10"=="20231010".tag_to_date,
|
21
|
+
["2023", "10", "10", "12", "30", "45"]=="20231010123045".tag_to_number,
|
22
|
+
"2023-10-10 12:30:45"=="20231010123045".tag_to_datetime,
|
23
|
+
"Tuesday"=="2023-10-10".weekday,
|
24
|
+
"Tuesday"==Time.new(2023, 10, 10).weekday,
|
25
|
+
"Tuesday"==DateTime.new(2023, 10, 10).weekday,
|
26
|
+
"2023-10-10"==Time.new(2023, 10, 10).date,
|
27
|
+
"2023-10-10"==DateTime.new(2023, 10, 10).date,
|
28
|
+
"12:30:45"==Time.new(2023, 10, 10, 12, 30, 45).time,
|
29
|
+
"12:30:45"==DateTime.new(2023, 10, 10, 12, 30, 45).time,
|
30
|
+
"2023-10-10 12:30:45"==Time.new(2023, 10, 10, 12, 30, 45).form,
|
31
|
+
"2023-10-10 12:30:45"==DateTime.new(2023, 10, 10, 12, 30, 45).form,
|
32
|
+
"20231010123045"==Time.new(2023, 10, 10, 12, 30, 45).tag,
|
33
|
+
"20231010123045"==DateTime.new(2023, 10, 10, 12, 30, 45).tag,
|
34
|
+
Time.new(2023, 10, 10, 12, 30, 45)==Time.form("2023-10-10 12:30:45"),
|
35
|
+
DateTime.new(2023, 10, 10, 12, 30, 45)==DateTime.form("2023-10-10 12:30:45"),
|
36
|
+
Time.new.strftime('%Y%m%d%H%M%S')==Time.tag,
|
37
|
+
DateTime.new.strftime('%Y%m%d%H%M%S')==DateTime.tag,
|
38
|
+
1==1.sec,
|
39
|
+
60==1.min,
|
40
|
+
3600==1.hour
|
41
|
+
=end
|
42
|
+
|
43
|
+
class String
|
44
|
+
def time
|
45
|
+
# date = /[0-9]+\-[0-9]+\-[0-9]+/.match(self)
|
46
|
+
# time = /[0-9]+\:[0-9]+\:[0-9]+/.match(self)
|
47
|
+
# year, month, day = date.to_s.split("-")
|
48
|
+
# hour, minute, second = time.to_s.split(":")
|
49
|
+
itime = Time.parse(self)
|
50
|
+
return itime.year||Time.now.year, itime.month||Time.now.month,
|
51
|
+
itime.day||Time.now.day,itime.hour||Time.now.hour,
|
52
|
+
itime.min||Time.now.min, itime.sec||Time.now.sec
|
53
|
+
end
|
54
|
+
|
55
|
+
def tag_to_numtime
|
56
|
+
return [] unless self.size==6
|
57
|
+
return self.unpack("a2a2a2")
|
58
|
+
end
|
59
|
+
|
60
|
+
def tag_to_time
|
61
|
+
return nil unless self.size==6
|
62
|
+
return self.unpack("a2a2a2").join(":")
|
63
|
+
end
|
64
|
+
|
65
|
+
def tag_to_numdate
|
66
|
+
return [] unless self.size==8
|
67
|
+
return self.unpack("a4a2a2")
|
68
|
+
end
|
69
|
+
|
70
|
+
def tag_to_date
|
71
|
+
return nil unless self.size==8
|
72
|
+
return self.unpack("a4a2a2").join("-")
|
73
|
+
end
|
74
|
+
|
75
|
+
def tag_to_number
|
76
|
+
return [] unless self.size==14
|
77
|
+
return self[0..7].tag_to_numdate+self[-6..-1].tag_to_numtime
|
78
|
+
end
|
79
|
+
|
80
|
+
def tag_to_datetime
|
81
|
+
return nil unless self.size==14
|
82
|
+
return self[0..7].tag_to_date+" "+self[-6..-1].tag_to_time
|
83
|
+
end
|
84
|
+
|
85
|
+
def weekday
|
86
|
+
Time.form(self).weekday
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
class Time
|
91
|
+
def weekday
|
92
|
+
self.strftime('%A')
|
93
|
+
end
|
94
|
+
|
95
|
+
def date
|
96
|
+
self.strftime("%Y-%m-%d")
|
97
|
+
end
|
98
|
+
|
99
|
+
def time
|
100
|
+
self.strftime("%H:%M:%S")
|
101
|
+
end
|
102
|
+
|
103
|
+
def form
|
104
|
+
self.strftime("%Y-%m-%d %H:%M:%S")
|
105
|
+
end
|
106
|
+
|
107
|
+
def tag
|
108
|
+
self.strftime("%Y%m%d%H%M%S")
|
109
|
+
end
|
110
|
+
|
111
|
+
def self.form string
|
112
|
+
Time.new *string.time
|
113
|
+
end
|
114
|
+
|
115
|
+
def self.tag
|
116
|
+
Time.new.strftime('%Y%m%d%H%M%S')
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
class DateTime
|
121
|
+
def weekday
|
122
|
+
self.strftime('%A')
|
123
|
+
end
|
124
|
+
|
125
|
+
def date
|
126
|
+
self.strftime("%Y-%m-%d")
|
127
|
+
end
|
128
|
+
|
129
|
+
def time
|
130
|
+
self.strftime("%H:%M:%S")
|
131
|
+
end
|
132
|
+
|
133
|
+
def form
|
134
|
+
self.strftime("%Y-%m-%d %H:%M:%S")
|
135
|
+
end
|
136
|
+
|
137
|
+
def tag
|
138
|
+
self.strftime("%Y%m%d%H%M%S")
|
139
|
+
end
|
140
|
+
|
141
|
+
def self.form string
|
142
|
+
DateTime.new *string.time
|
143
|
+
end
|
144
|
+
|
145
|
+
def self.tag
|
146
|
+
DateTime.new.strftime('%Y%m%d%H%M%S')
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
class Integer
|
151
|
+
def min
|
152
|
+
sec = self*60
|
153
|
+
end
|
154
|
+
|
155
|
+
def hour
|
156
|
+
sec = self*3600
|
157
|
+
end
|
158
|
+
|
159
|
+
def sec
|
160
|
+
sec = self
|
161
|
+
end
|
162
|
+
end
|
data/enum.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
#coding:utf-8
|
2
|
+
|
3
|
+
############################################################################################################
|
4
|
+
# HOW TO USE #
|
5
|
+
############################################################################################################
|
6
|
+
|
7
|
+
=begin
|
8
|
+
require 'cc'
|
9
|
+
CC.use 'enum' # immediately when loading this file
|
10
|
+
|
11
|
+
puts "Enumberable objects could be classified by customize criterions:"
|
12
|
+
pp (1..10).classify{|x|x%3}
|
13
|
+
|
14
|
+
puts "Enumberable objects could be added head or tail:"
|
15
|
+
pp [ 1 , [2], 3 ].unfold_head( :a, :b, :c )
|
16
|
+
pp [[1], 2 , [3]].unfold_tail(*[:x, :y, :z])
|
17
|
+
=end
|
18
|
+
|
19
|
+
module Enumerable
|
20
|
+
def classify (&block)
|
21
|
+
hash = {}
|
22
|
+
self.each do|x|
|
23
|
+
result = block.call(x)
|
24
|
+
(hash[result] ||= []) << x
|
25
|
+
end
|
26
|
+
return hash
|
27
|
+
end
|
28
|
+
|
29
|
+
def add_head *one
|
30
|
+
new_array = []
|
31
|
+
self.each do|item|
|
32
|
+
new_array << ( item.instance_of?(Array) ? one+item : one+[item] )
|
33
|
+
end
|
34
|
+
return new_array
|
35
|
+
end
|
36
|
+
|
37
|
+
def add_tail *one
|
38
|
+
new_array = []
|
39
|
+
self.each do|item|
|
40
|
+
new_array << ( item.instance_of?(Array) ? item+one : [item]+one )
|
41
|
+
end
|
42
|
+
return new_array
|
43
|
+
end
|
44
|
+
|
45
|
+
alias :unfold_head :add_head
|
46
|
+
alias :unfold_tail :add_tail
|
47
|
+
end
|
data/exception.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
#coding:utf-8
|
2
|
+
|
3
|
+
############################################################################################################
|
4
|
+
# HOW TO USE #
|
5
|
+
############################################################################################################
|
6
|
+
|
7
|
+
=begin
|
8
|
+
require 'cc'
|
9
|
+
CC.use 'exception' # immediately when loading this file
|
10
|
+
|
11
|
+
begin
|
12
|
+
raise "When trigger an error."
|
13
|
+
rescue => exp
|
14
|
+
puts exp.info
|
15
|
+
end
|
16
|
+
|
17
|
+
obj = Object.new
|
18
|
+
obj.extend Insight
|
19
|
+
|
20
|
+
puts "\nWhen calling unknown methods:"
|
21
|
+
obj.some_method()
|
22
|
+
obj.another_method("hello", 1, "world")
|
23
|
+
puts obj.unknown_callings.inspect
|
24
|
+
|
25
|
+
@person = Object.new
|
26
|
+
class << @person
|
27
|
+
def first_name() 'A' end
|
28
|
+
def last_name() 'Z' end
|
29
|
+
end
|
30
|
+
|
31
|
+
puts "\nWhen calling an unknown method, it will return nil:"
|
32
|
+
p @person.try(:name)
|
33
|
+
|
34
|
+
puts "\nWhen calling a definite process, it will try to run:"
|
35
|
+
p @person.try{|p|"#{p.first_name} #{p.last_name}"}
|
36
|
+
|
37
|
+
puts "\nWhen calling a defect process, it will respond to rescue:"
|
38
|
+
taste proc: proc{1/0}, rescue: proc{p 'Here is final presentation.'}
|
39
|
+
=end
|
40
|
+
|
41
|
+
class Exception
|
42
|
+
def self.text instance
|
43
|
+
return "SystemError:"+
|
44
|
+
"#{instance.backtrace[0]}: #{instance.message}(#{instance.class})"+
|
45
|
+
"#{"\n\tfrom "<<instance.backtrace[1..-1].map{|i|i.encode("UTF-8")}.join("\n")}" if instance.is_a?(Exception)
|
46
|
+
end
|
47
|
+
|
48
|
+
def info
|
49
|
+
return self.class.text(self)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
module Insight
|
54
|
+
def unknown_callings
|
55
|
+
@unknown_callings ||= []
|
56
|
+
end
|
57
|
+
|
58
|
+
def method_missing name,*args
|
59
|
+
@unknown_callings ||= []
|
60
|
+
@unknown_callings << "#{name}(#{args.join(",")})"
|
61
|
+
warn "Unknown calling: #{@unknown_callings[-1]}"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
class Object
|
66
|
+
def try(*a, &b)
|
67
|
+
if a.empty? && block_given?
|
68
|
+
yield self
|
69
|
+
else
|
70
|
+
public_send(*a, &b) if respond_to?(a.first)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
class NilClass
|
76
|
+
def try(*args)
|
77
|
+
nil
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def taste transacation={} # proc: λ{}, rescue: λ{}, params: *arguments
|
82
|
+
process = transacation[:proc]
|
83
|
+
recover = transacation[:rescue] || lambda{}
|
84
|
+
params = transacation[:params] || []
|
85
|
+
begin
|
86
|
+
process.call
|
87
|
+
rescue Exception => exp
|
88
|
+
puts Exception.text(exp)
|
89
|
+
recover.call(*params)
|
90
|
+
end
|
91
|
+
end
|