mpatch 1.3.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/README.md +32 -0
- data/VERSION +1 -1
- data/lib/mpatch/array.rb +119 -117
- data/lib/mpatch/class.rb +68 -66
- data/lib/mpatch/file.rb +35 -37
- data/lib/mpatch/hash.rb +93 -91
- data/lib/mpatch/integer.rb +10 -8
- data/lib/mpatch/module.rb +13 -11
- data/lib/mpatch/object.rb +211 -196
- data/lib/mpatch/proc.rb +11 -9
- data/lib/mpatch/process.rb +11 -22
- data/lib/mpatch/random.rb +41 -32
- data/lib/mpatch/string.rb +65 -63
- data/lib/mpatch/yml.rb +11 -7
- data/lib/mpatch.rb +33 -0
- data/mpatch.gemspec +0 -2
- metadata +6 -24
- data/lib/mpatch/boolean.rb +0 -15
- data/lib/mpatch/exception.rb +0 -0
- data/lib/mpatch/kernel.rb +0 -10
- data/lib/mpatch/str2duck.rb +0 -1
data/lib/mpatch/string.rb
CHANGED
@@ -1,78 +1,80 @@
|
|
1
|
-
|
1
|
+
module MPatch
|
2
|
+
module String
|
2
3
|
|
3
|
-
|
4
|
-
|
4
|
+
# Find string in othere string
|
5
|
+
def positions(oth_string)
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
special_chrs=%w[# _ & < > @ $ . , -]+[*(0..9)]+[*("A".."Z")]+[*("a".."z")]
|
8
|
+
loop do
|
9
|
+
if oth_string.include? special_chrs[0]
|
10
|
+
special_chrs.shift
|
11
|
+
else
|
12
|
+
break
|
13
|
+
end
|
12
14
|
end
|
13
|
-
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
16
|
+
string=self
|
17
|
+
return_array = []
|
18
|
+
loop do
|
19
|
+
break if string.index(oth_string).nil?
|
20
|
+
range_value= ((string.index(oth_string))..(string.index(oth_string)+oth_string.length-1))
|
21
|
+
return_array.push range_value
|
22
|
+
[*range_value].each do |one_index|
|
23
|
+
string[one_index]= special_chrs[0]
|
24
|
+
end
|
23
25
|
end
|
24
|
-
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
# Standard in rails. See official documentation
|
31
|
-
# [http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html]
|
32
|
-
def camelize(first_letter = :upper)
|
33
|
-
if first_letter == :upper
|
34
|
-
gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
|
35
|
-
else
|
36
|
-
self[0..0].downcase + camelize[1..-1]
|
27
|
+
# return value
|
28
|
+
return return_array
|
37
29
|
end
|
38
|
-
end unless method_defined? :camelize
|
39
30
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
31
|
+
# Standard in rails. See official documentation
|
32
|
+
# [http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html]
|
33
|
+
def camelize(first_letter = :upper)
|
34
|
+
if first_letter == :upper
|
35
|
+
gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
|
36
|
+
else
|
37
|
+
self[0..0].downcase + camelize[1..-1]
|
38
|
+
end
|
39
|
+
end unless method_defined? :camelize
|
40
|
+
|
41
|
+
# Standard in rails. See official documentation
|
42
|
+
# [http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html]
|
43
|
+
def dasherize
|
44
|
+
gsub(/_/, '-')
|
45
|
+
end unless method_defined? :dasherize
|
45
46
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
# Standard in rails. See official documentation
|
48
|
+
# [http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html]
|
49
|
+
def demodulize
|
50
|
+
gsub(/^.*::/, '')
|
51
|
+
end unless method_defined? :demodulize
|
51
52
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
53
|
+
# Standard in rails. See official documentation
|
54
|
+
# [http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html]
|
55
|
+
def underscore
|
56
|
+
gsub(/::/, '/').
|
57
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
58
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
59
|
+
tr("-", "_").
|
60
|
+
downcase
|
61
|
+
end unless method_defined? :underscore
|
61
62
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
63
|
+
# Check that instance of String is start with an upper case or not
|
64
|
+
def capitalized?
|
65
|
+
self.match(/^[[:upper:]]/) ? true : false
|
66
|
+
end
|
66
67
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
68
|
+
# return the number how often the str is with in the self
|
69
|
+
# by default with \b regex border
|
70
|
+
def frequency(str)
|
71
|
+
begin
|
72
|
+
if str.class == String
|
73
|
+
str= '\b'+str+'\b'
|
74
|
+
end
|
73
75
|
end
|
76
|
+
self.scan(/#{str}/).count
|
74
77
|
end
|
75
|
-
self.scan(/#{str}/).count
|
76
|
-
end
|
77
78
|
|
78
|
-
end
|
79
|
+
end
|
80
|
+
end
|
data/lib/mpatch/yml.rb
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
require 'yaml'
|
2
|
-
module YAML
|
3
|
-
def self.save_file(file_path,config_hash)
|
4
|
-
File.open(file_path, 'w+') {|f| f.write(config_hash.to_yaml) }
|
5
|
-
end
|
6
2
|
|
7
|
-
|
8
|
-
|
3
|
+
module MPatch
|
4
|
+
|
5
|
+
module YAML
|
6
|
+
def self.save_file(file_path,config_hash)
|
7
|
+
File.open(file_path, 'w+') {|f| f.write(config_hash.to_yaml) }
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.load_file(file_path)
|
11
|
+
YAML.load(File.open(file_path))
|
12
|
+
end
|
9
13
|
end
|
10
|
-
end
|
11
14
|
|
15
|
+
end
|
data/lib/mpatch.rb
CHANGED
@@ -3,4 +3,37 @@ module MPatch
|
|
3
3
|
|
4
4
|
Dir.glob(File.join(File.absolute_path(File.dirname(__FILE__)),"mpatch","**","*.{rb,ru}")).each{|e|require e}
|
5
5
|
|
6
|
+
[
|
7
|
+
MPatch::Process,
|
8
|
+
MPatch::String,
|
9
|
+
MPatch::Proc,
|
10
|
+
MPatch::YAML,
|
11
|
+
MPatch::Object,
|
12
|
+
MPatch::File,
|
13
|
+
MPatch::Array,
|
14
|
+
MPatch::Integer,
|
15
|
+
MPatch::Hash
|
16
|
+
].each do |module_name|
|
17
|
+
|
18
|
+
constant= ::Object
|
19
|
+
name= module_name.to_s.split('::').last
|
20
|
+
constant = constant.const_defined?(name, false) ? constant.const_get(name) : constant.const_missing(name)
|
21
|
+
|
22
|
+
constant.__send__ :include, module_name
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
[
|
27
|
+
MPatch::Random
|
28
|
+
].each do |module_name|
|
29
|
+
|
30
|
+
constant= ::Object
|
31
|
+
name= module_name.to_s.split('::').last
|
32
|
+
constant = constant.const_defined?(name, false) ? constant.const_get(name) : constant.const_missing(name)
|
33
|
+
|
34
|
+
constant.__send__ :extend, module_name
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
|
6
39
|
end
|
data/mpatch.gemspec
CHANGED
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mpatch
|
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-
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: str2duck
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ! '>='
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ! '>='
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
11
|
+
date: 2014-03-19 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
27
13
|
description: This is a collection of my Ruby monkey patches for making easer to use
|
28
14
|
the basic classes
|
29
15
|
email:
|
@@ -40,19 +26,15 @@ files:
|
|
40
26
|
- files.rb
|
41
27
|
- lib/mpatch.rb
|
42
28
|
- lib/mpatch/array.rb
|
43
|
-
- lib/mpatch/boolean.rb
|
44
29
|
- lib/mpatch/class.rb
|
45
|
-
- lib/mpatch/exception.rb
|
46
30
|
- lib/mpatch/file.rb
|
47
31
|
- lib/mpatch/hash.rb
|
48
32
|
- lib/mpatch/integer.rb
|
49
|
-
- lib/mpatch/kernel.rb
|
50
33
|
- lib/mpatch/module.rb
|
51
34
|
- lib/mpatch/object.rb
|
52
35
|
- lib/mpatch/proc.rb
|
53
36
|
- lib/mpatch/process.rb
|
54
37
|
- lib/mpatch/random.rb
|
55
|
-
- lib/mpatch/str2duck.rb
|
56
38
|
- lib/mpatch/string.rb
|
57
39
|
- lib/mpatch/yml.rb
|
58
40
|
- mpatch.gemspec
|
@@ -66,17 +48,17 @@ require_paths:
|
|
66
48
|
- lib
|
67
49
|
required_ruby_version: !ruby/object:Gem::Requirement
|
68
50
|
requirements:
|
69
|
-
- -
|
51
|
+
- - ">="
|
70
52
|
- !ruby/object:Gem::Version
|
71
53
|
version: '0'
|
72
54
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
55
|
requirements:
|
74
|
-
- -
|
56
|
+
- - ">="
|
75
57
|
- !ruby/object:Gem::Version
|
76
58
|
version: '0'
|
77
59
|
requirements: []
|
78
60
|
rubyforge_project:
|
79
|
-
rubygems_version: 2.2.
|
61
|
+
rubygems_version: 2.2.2
|
80
62
|
signing_key:
|
81
63
|
specification_version: 4
|
82
64
|
summary: collection of methods for extend basic classes
|
data/lib/mpatch/boolean.rb
DELETED
data/lib/mpatch/exception.rb
DELETED
File without changes
|
data/lib/mpatch/kernel.rb
DELETED
data/lib/mpatch/str2duck.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'str2duck'
|