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 +4 -4
- data/VERSION +1 -1
- data/dump/class_and_module.rb +45 -0
- data/examples/test.rb +4 -0
- data/lib/mpatch/array.rb +2 -1
- data/lib/mpatch/class.rb +1 -1
- data/lib/mpatch/hash.rb +1 -1
- data/lib/mpatch/integer.rb +1 -1
- data/lib/mpatch/module.rb +45 -5
- data/lib/mpatch/object.rb +1 -1
- data/lib/mpatch/proc.rb +1 -1
- data/lib/mpatch/process.rb +1 -1
- data/lib/mpatch/random.rb +1 -1
- data/lib/mpatch/string.rb +1 -1
- data/lib/mpatch/yml.rb +1 -1
- data/lib/mpatch.rb +34 -25
- metadata +4 -3
- data/lib/mpatch/class_and_module.rb +0 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7fed0e415d7673ca6e61bba8b1969b665b95205c
|
4
|
+
data.tar.gz: f2eb082eb9f833eea5e797b01a5bf169dc61efe8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83900da5b874f58ba33da62e05be2914893bcb080d02e775c16e8c4acc4d7650191aaf0da008099410a98f5a98d80f5ebe9fbbd29151134e7bb08c25a3e0a850
|
7
|
+
data.tar.gz: 2e682a38bc24e506aeddf287a83930f8ee0e1d0d7fb190accf208a6eee9846b73b3487861559fe69a3f1f0ca7f51be1a80daf870e7104ce8577671532b2da75c
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.2.
|
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
data/lib/mpatch/array.rb
CHANGED
data/lib/mpatch/class.rb
CHANGED
data/lib/mpatch/hash.rb
CHANGED
data/lib/mpatch/integer.rb
CHANGED
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
|
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
|
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 :
|
15
|
-
alias :
|
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
data/lib/mpatch/proc.rb
CHANGED
data/lib/mpatch/process.rb
CHANGED
data/lib/mpatch/random.rb
CHANGED
data/lib/mpatch/string.rb
CHANGED
data/lib/mpatch/yml.rb
CHANGED
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
|
-
|
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
|
-
|
22
|
-
|
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
|
-
|
17
|
+
constant= ::Object
|
18
|
+
constant_name= sub_module_name.to_s.split('::').last
|
19
|
+
array_of_target_constant= []
|
26
20
|
|
27
|
-
|
21
|
+
case true
|
28
22
|
|
29
|
-
|
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
|
-
|
32
|
-
|
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
|
-
|
31
|
+
end
|
36
32
|
|
37
|
-
|
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.
|
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-
|
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
|