mpatch 2.2.1 → 2.2.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2cbc8843bcb428bdd3ee7119c19e00bf08f251cf
4
- data.tar.gz: 53a12a8e35f450aa25a1bb4d9ccf06c05e40e9cf
3
+ metadata.gz: 7fed0e415d7673ca6e61bba8b1969b665b95205c
4
+ data.tar.gz: f2eb082eb9f833eea5e797b01a5bf169dc61efe8
5
5
  SHA512:
6
- metadata.gz: f32a8a90dc4ed94ca5a0198c73fb5ab7467ac82ad245744b3fd4b0be784a2b850f9ad5732fdce0f7c6f04caa83e3e365201cf3d478a28df20ebb4dff9a5cd9d1
7
- data.tar.gz: 440b60f05e81d06e009b0114abf37a5aa4f148943cca44e25740f4af8382f032517c0044c71f03e765a20c8410ba2a2366296821e15a6d48e5a711c5b0f09fee
6
+ metadata.gz: 83900da5b874f58ba33da62e05be2914893bcb080d02e775c16e8c4acc4d7650191aaf0da008099410a98f5a98d80f5ebe9fbbd29151134e7bb08c25a3e0a850
7
+ data.tar.gz: 2e682a38bc24e506aeddf287a83930f8ee0e1d0d7fb190accf208a6eee9846b73b3487861559fe69a3f1f0ca7f51be1a80daf870e7104ce8577671532b2da75c
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.2.1
1
+ 2.2.4
@@ -0,0 +1,45 @@
1
+ #module MPatch::Include
2
+ # module Module #ClassAndModule
3
+ #
4
+ # def mixin_ancestors(include_ancestors=true)
5
+ # ancestors.take_while {|a| include_ancestors || a != superclass }.
6
+ # select {|ancestor| ancestor.instance_of?( ::Module ) }
7
+ # end
8
+ #
9
+ # def inherited_by *args
10
+ #
11
+ # if args.empty?
12
+ # args.push(::Class)
13
+ # args.push(::Module)
14
+ # end
15
+ #
16
+ # return_array= []
17
+ # args.each do |type_name|
18
+ #
19
+ # ::ObjectSpace.each_object(type_name) do |candidate|
20
+ # begin
21
+ #
22
+ # if !return_array.include?(candidate) && candidate != self
23
+ # case self.class.to_s
24
+ #
25
+ # when "Module"
26
+ # return_array.push candidate if candidate.mixin_ancestors.include?(self)
27
+ #
28
+ # when "Class"
29
+ # return_array.push candidate if candidate < self
30
+ #
31
+ # end
32
+ #
33
+ # end
34
+ #
35
+ # rescue ::ArgumentError, ::NoMethodError
36
+ # end
37
+ # end
38
+ #
39
+ # end
40
+ # return_array
41
+ #
42
+ # end
43
+ #
44
+ # end
45
+ #end
data/examples/test.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'mpatch'
2
+
3
+ puts Module.ancestors.inspect
4
+ puts ["asd"].has_any_of?(["asd"])
data/lib/mpatch/array.rb CHANGED
@@ -1,4 +1,5 @@
1
- module MPatch
1
+ module MPatch::Include
2
+
2
3
  module Array
3
4
 
4
5
  # remove arguments or array of
data/lib/mpatch/class.rb CHANGED
@@ -1,4 +1,4 @@
1
- module MPatch
1
+ module MPatch::Include
2
2
  module Class
3
3
 
4
4
  # get singleton methods to target class without super class methods
data/lib/mpatch/hash.rb CHANGED
@@ -1,4 +1,4 @@
1
- module MPatch
1
+ module MPatch::Include
2
2
  module Hash
3
3
 
4
4
  # remove elements by keys,
@@ -1,5 +1,5 @@
1
1
 
2
- module MPatch
2
+ module MPatch::Include
3
3
  module Integer
4
4
 
5
5
  # because for i in integer/fixnum not working,
data/lib/mpatch/module.rb CHANGED
@@ -1,18 +1,58 @@
1
- module MPatch
1
+ module MPatch::Include
2
2
  module Module
3
3
 
4
4
  # return the module objects direct sub modules
5
- def modules
5
+ def submodules
6
6
  constants.collect {|const_name| const_get(const_name)}.select {|const| const.class == ::Module}
7
7
  end
8
8
 
9
9
  # return the module objects direct sub modules
10
- def classes
10
+ def subclasses
11
11
  constants.collect {|const_name| const_get(const_name)}.select {|const| const.class == ::Class}
12
12
  end
13
13
 
14
- alias :submodules :modules
15
- alias :subclasses :classes
14
+ alias :modules :submodules
15
+ alias :classes :subclasses
16
+
17
+ def mixin_ancestors(include_ancestors=true)
18
+ ancestors.take_while {|a| include_ancestors || a != superclass }.
19
+ select {|ancestor| ancestor.instance_of?( ::Module ) }
20
+ end
21
+
22
+ def inherited_by *args
23
+
24
+ if args.empty?
25
+ args.push(::Class)
26
+ args.push(::Module)
27
+ end
28
+
29
+ return_array= []
30
+ args.each do |type_name|
31
+
32
+ ::ObjectSpace.each_object(type_name) do |candidate|
33
+ begin
34
+
35
+ if !return_array.include?(candidate) && candidate != self
36
+ case self.class.to_s
37
+
38
+ when "Module"
39
+ return_array.push candidate if candidate.mixin_ancestors.include?(self)
40
+
41
+ when "Class"
42
+ return_array.push candidate if candidate < self
43
+
44
+ end
45
+
46
+ end
47
+
48
+ rescue ::ArgumentError, ::NoMethodError
49
+ end
50
+ end
51
+
52
+ end
53
+ return_array
54
+
55
+ end
16
56
 
17
57
  end
18
58
  end
data/lib/mpatch/object.rb CHANGED
@@ -1,4 +1,4 @@
1
- module MPatch
1
+ module MPatch::Include
2
2
  module Object
3
3
 
4
4
  def boolean?
data/lib/mpatch/proc.rb CHANGED
@@ -1,4 +1,4 @@
1
- module MPatch
1
+ module MPatch::Include
2
2
  module Proc
3
3
 
4
4
  # sugar syntax for proc * operator
@@ -1,4 +1,4 @@
1
- module MPatch
1
+ module MPatch::Extend
2
2
  module Process
3
3
 
4
4
  # return a string obj that include the memory usage info
data/lib/mpatch/random.rb CHANGED
@@ -1,4 +1,4 @@
1
- module MPatch
1
+ module MPatch::Extend
2
2
  module Random
3
3
 
4
4
  def string(length= 7,amount=1,hyphen= " ")
data/lib/mpatch/string.rb CHANGED
@@ -1,4 +1,4 @@
1
- module MPatch
1
+ module MPatch::Include
2
2
  module String
3
3
 
4
4
  # Find string in othere string
data/lib/mpatch/yml.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'yaml'
2
2
 
3
- module MPatch
3
+ module MPatch::Extend
4
4
 
5
5
  module YAML
6
6
  def save_file(file_path,config_hash)
data/lib/mpatch.rb CHANGED
@@ -1,40 +1,49 @@
1
1
  #encoding: UTF-8
2
2
  module MPatch
3
3
 
4
+ module Include;end
5
+ module Extend;end
6
+
4
7
  Dir.glob(File.join(File.absolute_path(File.dirname(__FILE__)),"mpatch","**","*.{rb,ru}")).each{|e|require e}
8
+ extend MPatch::Include::Module
5
9
 
6
- [ MPatch::Module, MPatch::Class ].each do |module_name|
7
- module_name.__send__ :include, MPatch::ClassAndModule
8
- end
10
+ self.submodules.each do |module_name|
9
11
 
10
- [
11
- MPatch::Module,
12
- MPatch::Class,
13
- MPatch::String,
14
- MPatch::Proc,
15
- MPatch::Object,
16
- MPatch::Array,
17
- MPatch::Integer,
18
- MPatch::Hash
19
- ].each do |module_name|
12
+ method_name= module_name.to_s.split('::').last.downcase.to_s.to_sym
20
13
 
21
- constant= ::Object
22
- name= module_name.to_s.split('::').last
23
- constant = constant.const_defined?(name, false) ? constant.const_get(name) : constant.const_missing(name)
14
+ module_name.__send__ :extend, MPatch::Include::Module
15
+ module_name.submodules.each do |sub_module_name|
24
16
 
25
- constant.__send__ :include, module_name
17
+ constant= ::Object
18
+ constant_name= sub_module_name.to_s.split('::').last
19
+ array_of_target_constant= []
26
20
 
27
- end
21
+ case true
28
22
 
29
- [ MPatch::Process, MPatch::Random, MPatch::YAML ].each do |module_name|
23
+ when sub_module_name.to_s.include?('And')
24
+ sub_module_name.to_s.split('::').last.split('And').each do |tag_module|
25
+ array_of_target_constant.push tag_module
26
+ end
30
27
 
31
- constant= ::Object
32
- name= module_name.to_s.split('::').last
33
- constant = constant.const_defined?(name, false) ? constant.const_get(name) : constant.const_missing(name)
28
+ else
29
+ array_of_target_constant.push constant_name
34
30
 
35
- constant.__send__ :extend, module_name
31
+ end
36
32
 
37
- end
33
+ array_of_target_constant.each do |name|
34
+
35
+ begin
36
+ target_constant = constant.const_defined?(name, false) ? constant.const_get(name) : constant.const_missing(name)
37
+ target_constant.__send__ method_name, sub_module_name
38
+ rescue ::NoMethodError => ex
39
+ STDERR.puts ex
40
+ end
38
41
 
42
+ end
43
+
44
+ end
45
+
46
+
47
+ end
39
48
 
40
- end
49
+ end
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.2.1
4
+ version: 2.2.4
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-03-26 00:00:00.000000000 Z
11
+ date: 2014-03-27 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
@@ -23,11 +23,12 @@ files:
23
23
  - Rakefile
24
24
  - VERSION
25
25
  - create_folder.rb
26
+ - dump/class_and_module.rb
27
+ - examples/test.rb
26
28
  - files.rb
27
29
  - lib/mpatch.rb
28
30
  - lib/mpatch/array.rb
29
31
  - lib/mpatch/class.rb
30
- - lib/mpatch/class_and_module.rb
31
32
  - lib/mpatch/hash.rb
32
33
  - lib/mpatch/integer.rb
33
34
  - lib/mpatch/module.rb
@@ -1,44 +0,0 @@
1
- module MPatch
2
- module ClassAndModule
3
- def mixin_ancestors(include_ancestors=true)
4
- ancestors.take_while {|a| include_ancestors || a != superclass }.
5
- select {|ancestor| ancestor.instance_of?( ::Module ) }
6
- end
7
-
8
- def inherited_by *args
9
-
10
- if args.empty?
11
- args.push(::Class)
12
- args.push(::Module)
13
- end
14
-
15
- return_array= []
16
- args.each do |type_name|
17
-
18
- ::ObjectSpace.each_object(type_name) do |candidate|
19
- begin
20
-
21
- if !return_array.include?(candidate) && candidate != self
22
- case self.class.to_s
23
-
24
- when "Module"
25
- return_array.push candidate if candidate.mixin_ancestors.include?(self)
26
-
27
- when "Class"
28
- return_array.push candidate if candidate < self
29
-
30
- end
31
-
32
- end
33
-
34
- rescue ::ArgumentError, ::NoMethodError
35
- end
36
- end
37
-
38
- end
39
- return_array
40
-
41
- end
42
-
43
- end
44
- end