mpatch 1.3.0 → 2.0.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.
data/lib/mpatch/string.rb CHANGED
@@ -1,78 +1,80 @@
1
- class String
1
+ module MPatch
2
+ module String
2
3
 
3
- # Find string in othere string
4
- def positions(oth_string)
4
+ # Find string in othere string
5
+ def positions(oth_string)
5
6
 
6
- special_chrs=%w[# _ & < > @ $ . , -]+[*(0..9)]+[*("A".."Z")]+[*("a".."z")]
7
- loop do
8
- if oth_string.include? special_chrs[0]
9
- special_chrs.shift
10
- else
11
- break
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
- string=self
16
- return_array = Array.new
17
- loop do
18
- break if string.index(oth_string).nil?
19
- range_value= ((string.index(oth_string))..(string.index(oth_string)+oth_string.length-1))
20
- return_array.push range_value
21
- [*range_value].each do |one_index|
22
- string[one_index]= special_chrs[0]
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
- # return value
27
- return return_array
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
- # Standard in rails. See official documentation
41
- # [http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html]
42
- def dasherize
43
- gsub(/_/, '-')
44
- end unless method_defined? :dasherize
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
- # Standard in rails. See official documentation
47
- # [http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html]
48
- def demodulize
49
- gsub(/^.*::/, '')
50
- end unless method_defined? :demodulize
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
- # Standard in rails. See official documentation
53
- # [http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html]
54
- def underscore
55
- gsub(/::/, '/').
56
- gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
57
- gsub(/([a-z\d])([A-Z])/,'\1_\2').
58
- tr("-", "_").
59
- downcase
60
- end unless method_defined? :underscore
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
- # Check that instance of String is start with an upper case or not
63
- def capitalized?
64
- self.match(/^[[:upper:]]/) ? true : false
65
- end
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
- # return the number how often the str is with in the self
68
- # by default with \b regex border
69
- def frequency(str)
70
- begin
71
- if str.class == String
72
- str= '\b'+str+'\b'
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
- def self.load_file(file_path)
8
- YAML.load(File.open(file_path))
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
@@ -19,6 +19,4 @@ Gem::Specification.new do |spec|
19
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_dependency "str2duck"
23
-
24
22
  end
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: 1.3.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-02-27 00:00:00.000000000 Z
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.1
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
@@ -1,15 +0,0 @@
1
- class Object
2
-
3
- def boolean?
4
- !!self == self
5
- end
6
-
7
- def true?
8
- self == true
9
- end
10
-
11
- def false?
12
- self == false
13
- end
14
-
15
- end
File without changes
data/lib/mpatch/kernel.rb DELETED
@@ -1,10 +0,0 @@
1
- module Kernel
2
- def putsf(integer,*args)
3
- command_string=String.new
4
- args.each do |one_element|
5
- command_string+="%-#{integer}s"
6
- end
7
- command_string+="\n"
8
- printf command_string,*args
9
- end
10
- end
@@ -1 +0,0 @@
1
- require 'str2duck'