retroactive_module_inclusion 1.0.3 → 1.1.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.tar.gz.sig +0 -0
- data/.yardopts +3 -0
- data/History.rdoc +13 -1
- data/Manifest.txt +1 -0
- data/README.rdoc +2 -2
- data/Rakefile +22 -1
- data/lib/retroactive_module_inclusion.rb +53 -47
- metadata +5 -4
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
Binary file
|
data/.yardopts
ADDED
data/History.rdoc
CHANGED
@@ -1,8 +1,20 @@
|
|
1
|
+
=== 1.1.0 / 2011-01-22
|
2
|
+
|
3
|
+
* 2 minor enhancements
|
4
|
+
|
5
|
+
* Refactored retroactively_include method from ::Module to
|
6
|
+
CoreExt::Module::RetroactiveModuleInclusion, after Ola Bini suggested
|
7
|
+
in his post {SAFE(R) MONKEY PATCHING}[http://olabini.com/blog/2011/01/safeer-monkey-patching/]
|
8
|
+
|
9
|
+
* Finally, managed to make yard document the retroactively_include method:
|
10
|
+
* .yardopts had to be created to add the '--private' argument, because
|
11
|
+
yard ignores the rdoc document modifiers :doc: and :nodoc:
|
12
|
+
|
1
13
|
=== 1.0.3 / 2011-01-20
|
2
14
|
|
3
15
|
* 1 minor enhancement
|
4
16
|
|
5
|
-
*
|
17
|
+
* More concise Stats implementation, minor gem description and doc improvements
|
6
18
|
|
7
19
|
=== 1.0.1 / 2011-01-20
|
8
20
|
|
data/Manifest.txt
CHANGED
data/README.rdoc
CHANGED
@@ -55,9 +55,9 @@ The second, more concise and elegant, is to use this gem
|
|
55
55
|
|
56
56
|
Enumerable.module_eval { retroactively_include Stats }
|
57
57
|
|
58
|
-
== FEATURES
|
58
|
+
== FEATURES:
|
59
59
|
|
60
|
-
* Tested on all major Ruby interpreters (100% coverage, 0%
|
60
|
+
* Tested on all major Ruby interpreters (100% coverage, 0% failure):
|
61
61
|
* ruby-1.9.2-p136
|
62
62
|
* ruby-1.8.7-p330
|
63
63
|
* ree-1.8.7-2010.02
|
data/Rakefile
CHANGED
@@ -8,7 +8,7 @@ require 'hoe'
|
|
8
8
|
Hoe.spec 'retroactive_module_inclusion' do
|
9
9
|
developer('Adriano Mitre', 'adriano.mitre@gmail.com')
|
10
10
|
|
11
|
-
self.version = '1.0
|
11
|
+
self.version = '1.1.0'
|
12
12
|
|
13
13
|
self.readme_file = 'README.rdoc'
|
14
14
|
self.history_file = 'History.rdoc'
|
@@ -33,3 +33,24 @@ task :tests => [:test] do
|
|
33
33
|
# aliasing :test with :tests for RVM ('rvm tests')
|
34
34
|
end
|
35
35
|
|
36
|
+
module CoreExt
|
37
|
+
module String
|
38
|
+
module FromHere
|
39
|
+
def from_here
|
40
|
+
unless Dir.pwd != File.dirname(File.expand_path(__FILE__))
|
41
|
+
self
|
42
|
+
else
|
43
|
+
File.expand_path("../#{self}", __FILE__)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
String.class_eval { include CoreExt::String::FromHere }
|
51
|
+
|
52
|
+
task :clean_all => [:clean] do
|
53
|
+
%w{ .yardoc }.each do |rel_path|
|
54
|
+
rm_r rel_path.from_here if File.exist?(rel_path.from_here)
|
55
|
+
end
|
56
|
+
end
|
@@ -1,54 +1,60 @@
|
|
1
|
-
|
1
|
+
module CoreExt
|
2
|
+
module Module
|
3
|
+
module RetroactiveModuleInclusion
|
2
4
|
|
3
|
-
|
5
|
+
private
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
raise TypeError, 'wrong argument type #{mod.class} (expected Module)' unless mod.is_a? Module
|
7
|
+
# Includes +mod+ retroactively, i.e., extending to all classes and modules which
|
8
|
+
# had included +self+ _beforehand_.
|
9
|
+
#
|
10
|
+
# Example:
|
11
|
+
#
|
12
|
+
# module Stats
|
13
|
+
# def mean
|
14
|
+
# inject(&:+) / count.to_f
|
15
|
+
# end
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# Enumerable.module_eval { retroactively_include Stats }
|
19
|
+
#
|
20
|
+
# (1..2).mean #=> 1.5
|
21
|
+
#
|
22
|
+
def retroactively_include(mod) # :doc:
|
23
|
+
raise TypeError, "wrong argument type #{mod.class} (expected Module)" unless mod.is_a? ::Module # ::Module would in general be equivalent to Object::Module and simply Module would mean CoreExt::Module in this context
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
25
|
+
# Although one would expect +A.module_eval("include B")+ to make methods
|
26
|
+
# from module +B+ available to all classes and modules that had previously
|
27
|
+
# included module +A+, this is not the case due to a limitation in Ruby's
|
28
|
+
# object model (see [dynamic module include problem][1]). Thus, one has two
|
29
|
+
# possible solutions:
|
30
|
+
# * use Module#include_retroactively instead of Module#include
|
31
|
+
# * reopen +A+ and define the methods directly inside it
|
32
|
+
#
|
33
|
+
# JRuby (at least up to version 1.5.6) has ObjectSpace disabled by default,
|
34
|
+
# thus it must be enabled manually ([reference][2]).
|
35
|
+
#
|
36
|
+
# [1]: http://eigenclass.org/hiki/The+double+inclusion+problem "Dynamic Module Include Problem"
|
37
|
+
# [2]: http://ola-bini.blogspot.com/2007/07/objectspace-to-have-or-not-to-have.html "ObjectSpace: to have or not to have"
|
38
|
+
#
|
39
|
+
prev_jruby_objectspace_state = nil # only for scope reasons
|
40
|
+
if defined?(RUBY_DESCRIPTION) && RUBY_DESCRIPTION =~ /jruby/i
|
41
|
+
require 'jruby'
|
42
|
+
prev_jruby_objectspace_state = JRuby.objectspace
|
43
|
+
JRuby.objectspace = true
|
44
|
+
end
|
45
|
+
ObjectSpace.each_object(::Module) do |m|
|
46
|
+
if m <= self # equiv. to "if m.include?(self) || m == self"
|
47
|
+
m.module_eval { include mod }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
if defined?(RUBY_DESCRIPTION) && RUBY_DESCRIPTION =~ /jruby/i
|
51
|
+
JRuby.objectspace = prev_jruby_objectspace_state
|
52
|
+
end
|
47
53
|
end
|
48
|
-
|
49
|
-
|
50
|
-
|
54
|
+
|
55
|
+
::Module.class_eval { include CoreExt::Module::RetroactiveModuleInclusion }
|
56
|
+
|
51
57
|
end
|
52
58
|
end
|
53
|
-
|
54
59
|
end
|
60
|
+
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: retroactive_module_inclusion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 1.0.3
|
10
|
+
version: 1.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Adriano Mitre
|
@@ -36,7 +36,7 @@ cert_chain:
|
|
36
36
|
9u8N6mQNneIVRh6Xfdko/Q==
|
37
37
|
-----END CERTIFICATE-----
|
38
38
|
|
39
|
-
date: 2011-01-
|
39
|
+
date: 2011-01-22 00:00:00 -02:00
|
40
40
|
default_executable:
|
41
41
|
dependencies:
|
42
42
|
- !ruby/object:Gem::Dependency
|
@@ -76,6 +76,7 @@ extra_rdoc_files:
|
|
76
76
|
- History.rdoc
|
77
77
|
files:
|
78
78
|
- .autotest
|
79
|
+
- .yardopts
|
79
80
|
- History.rdoc
|
80
81
|
- Manifest.txt
|
81
82
|
- README.rdoc
|
metadata.gz.sig
CHANGED
Binary file
|