mpatch 2.7.0 → 2.8.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 +4 -4
- data/README.md +2 -0
- data/VERSION +1 -1
- data/lib/mpatch/method.rb +60 -0
- data/lib/mpatch/object.rb +3 -43
- data/test/test.rb +32 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c83a2235fa0593775a3614b626e8096ffd9bf428
|
4
|
+
data.tar.gz: 04557bd6c3ce119162e1fdf97673a4979924e828
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d16553211e2f477117fbe06777e07cf17bec4c5a13b893339579fddf534a2296503fba2c73a665af5b093b0c517ea001d778b1411fee39a821324364a9545e7
|
7
|
+
data.tar.gz: 63c7bdb2d8fbfb3ffbda713c2ee97d7e39a210c1fd8b6c0aab04ea5123c9e7d1b202c7490cdd3198c74ea73d352844ad039dbb03662bac6ced6c43e2faafc686
|
data/README.md
CHANGED
@@ -167,6 +167,8 @@ you can make an object / class / module instance or self methods private even fr
|
|
167
167
|
|
168
168
|
```
|
169
169
|
|
170
|
+
### After words
|
171
|
+
|
170
172
|
But there is a lot of method, for example for modules modules / subbmodules call that retunr modules under that namespace.
|
171
173
|
Lot of metaprogrammer stuff there too :)
|
172
174
|
|
data/VERSION
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
2.
|
1
|
+
2.8.0
|
2
2
|
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module MPatch
|
2
|
+
|
3
|
+
module Include
|
4
|
+
|
5
|
+
module Method
|
6
|
+
|
7
|
+
def get_comments
|
8
|
+
|
9
|
+
var= self.source_location.map{|obj| obj.class <= String ? File.absolute_path(obj) : obj }
|
10
|
+
|
11
|
+
file_obj= File.open(var[0],"r")
|
12
|
+
file_data= [] #> [*File.open(var[0],"r")]
|
13
|
+
var[1].times{ file_data.push file_obj.gets }
|
14
|
+
file_data.reverse!
|
15
|
+
|
16
|
+
desc_array= []
|
17
|
+
|
18
|
+
first= true
|
19
|
+
file_data.each { |new_string_line|
|
20
|
+
|
21
|
+
if first == true
|
22
|
+
first= false
|
23
|
+
next
|
24
|
+
end
|
25
|
+
|
26
|
+
if new_string_line =~ /^[\s\t]*(#[\s\S]*)?$/
|
27
|
+
|
28
|
+
unless new_string_line.scan(/^[\s\t]*(#\s*)([\s\S]*)?$/).empty?
|
29
|
+
new_string_line.replace new_string_line.scan(/^[\s\t]*(#\s*)([\s\S]*)?$/)[0][1]
|
30
|
+
end
|
31
|
+
|
32
|
+
if new_string_line.chomp =~ /^\s*$/
|
33
|
+
next
|
34
|
+
end
|
35
|
+
|
36
|
+
desc_array.push new_string_line.chomp
|
37
|
+
|
38
|
+
else
|
39
|
+
break
|
40
|
+
end
|
41
|
+
|
42
|
+
}
|
43
|
+
|
44
|
+
#remove nils
|
45
|
+
desc_array.compact!
|
46
|
+
|
47
|
+
# return
|
48
|
+
return desc_array.join("\n")
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
alias :get_description :get_comments
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
require File.join 'mpatch','injector'
|
59
|
+
|
60
|
+
end
|
data/lib/mpatch/object.rb
CHANGED
@@ -177,7 +177,7 @@ module MPatch
|
|
177
177
|
# privatize ex: Symbol/String/Array #> you can use this for make exceptions what should be not touched in the prcs
|
178
178
|
# privatize in: Symbol/String/Array #> you can use this for make targeted collection of methods for privatize
|
179
179
|
#
|
180
|
-
def privatize opts= {}
|
180
|
+
def privatize( opts= {} )
|
181
181
|
|
182
182
|
unless opts.class <= Hash
|
183
183
|
raise ArgumentError,"invalid input for options"
|
@@ -214,7 +214,6 @@ module MPatch
|
|
214
214
|
else
|
215
215
|
opts[:target]= 's'
|
216
216
|
opts[:include] ||= self.methods.map{|e| e.to_s }
|
217
|
-
|
218
217
|
end
|
219
218
|
|
220
219
|
[:include,:exclude].each do |array_name|
|
@@ -227,7 +226,7 @@ module MPatch
|
|
227
226
|
|
228
227
|
end
|
229
228
|
|
230
|
-
opts[:exclude]
|
229
|
+
opts[:exclude] + %W[ __send__ object_id ]
|
231
230
|
|
232
231
|
if opts[:target][0] == 's'
|
233
232
|
|
@@ -259,49 +258,10 @@ module MPatch
|
|
259
258
|
|
260
259
|
end
|
261
260
|
|
262
|
-
|
263
|
-
|
264
|
-
def try(exception= Exception,&block)
|
265
|
-
|
266
|
-
unless exception <= Exception
|
267
|
-
raise ArgumentError, "invalid exception class"
|
268
|
-
end
|
269
|
-
|
270
|
-
begin
|
271
|
-
return block.call
|
272
|
-
rescue exception => ex
|
273
|
-
@ruby_try_block_exception_tunel= ex
|
274
|
-
return ex
|
275
|
-
end
|
276
|
-
|
277
|
-
end
|
278
|
-
|
279
|
-
def catch exception = Exception, &block
|
280
|
-
|
281
|
-
if @ruby_try_block_exception_tunel.nil?
|
282
|
-
return nil
|
283
|
-
end
|
284
|
-
|
285
|
-
if @ruby_try_block_exception_tunel.class <= Exception
|
286
|
-
|
287
|
-
begin
|
288
|
-
block.call @ruby_try_block_exception_tunel
|
289
|
-
rescue ArgumentError
|
290
|
-
block.call
|
291
|
-
end
|
292
|
-
|
293
|
-
else
|
294
|
-
raise @ruby_try_block_exception_tunel.class,@ruby_try_block_exception_tunel.to_s
|
295
|
-
end
|
296
|
-
|
297
|
-
end
|
298
|
-
|
299
|
-
|
300
261
|
end
|
301
262
|
|
302
263
|
end
|
303
264
|
|
304
265
|
require File.join 'mpatch','injector'
|
305
266
|
|
306
|
-
|
307
|
-
end
|
267
|
+
end
|
data/test/test.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
require_relative '../lib/mpatch/object'
|
3
|
+
MPatch.patch!
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
try { hello world }
|
8
|
+
catch{ "not hello world " }
|
9
|
+
#> "not hello world"
|
10
|
+
|
11
|
+
|
12
|
+
try { "hello world".asdaf }
|
13
|
+
catch( NoMethodError ) { |ex|
|
14
|
+
puts "there is and error, because #{ex}"
|
15
|
+
}
|
16
|
+
|
17
|
+
#> you can cain up multiple catch for specific error
|
18
|
+
try { "hello world".asdaf }
|
19
|
+
catch( NoMethodError ) { |ex|
|
20
|
+
puts "there is and error, because #{ex}"
|
21
|
+
}
|
22
|
+
|
23
|
+
try { "hello world".asdaf }
|
24
|
+
catch(ArgumentError) {
|
25
|
+
puts "it was and argument error"
|
26
|
+
}
|
27
|
+
|
28
|
+
catch( NoMethodError ) { |ex|
|
29
|
+
puts "bla bla #{ex}"
|
30
|
+
}
|
31
|
+
|
32
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mpatch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.8.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-04-
|
11
|
+
date: 2014-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: This is a collection of my Ruby monkey patches for making easer to use
|
14
14
|
the basic classes
|
@@ -34,6 +34,7 @@ files:
|
|
34
34
|
- lib/mpatch/hash.rb
|
35
35
|
- lib/mpatch/injector.rb
|
36
36
|
- lib/mpatch/integer.rb
|
37
|
+
- lib/mpatch/method.rb
|
37
38
|
- lib/mpatch/module.rb
|
38
39
|
- lib/mpatch/object.rb
|
39
40
|
- lib/mpatch/proc.rb
|
@@ -42,6 +43,7 @@ files:
|
|
42
43
|
- lib/mpatch/string.rb
|
43
44
|
- lib/mpatch/yml.rb
|
44
45
|
- mpatch.gemspec
|
46
|
+
- test/test.rb
|
45
47
|
homepage: https://github.com/adamluzsi/mpatch
|
46
48
|
licenses:
|
47
49
|
- MIT
|
@@ -66,4 +68,5 @@ rubygems_version: 2.2.2
|
|
66
68
|
signing_key:
|
67
69
|
specification_version: 4
|
68
70
|
summary: collection of methods for extend basic classes
|
69
|
-
test_files:
|
71
|
+
test_files:
|
72
|
+
- test/test.rb
|