retroactive_module_inclusion 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/History.rdoc +6 -0
- data/Rakefile +1 -1
- data/lib/retroactive_module_inclusion.rb +17 -1
- metadata +2 -2
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
Binary file
|
data/History.rdoc
CHANGED
data/Rakefile
CHANGED
@@ -2,7 +2,23 @@ class Module
|
|
2
2
|
|
3
3
|
private
|
4
4
|
|
5
|
-
|
5
|
+
# Includes +mod+ retroactively, i.e., extending to all classes and modules which
|
6
|
+
# included +self+ _beforehand_.
|
7
|
+
#
|
8
|
+
# Example:
|
9
|
+
#
|
10
|
+
# module Stats
|
11
|
+
# def mean
|
12
|
+
# n = 1
|
13
|
+
# inject {|s,k| n += 1 ; s + k }.to_f / count
|
14
|
+
# end
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# Enumerable.module_eval { retroactively_include Stats }
|
18
|
+
#
|
19
|
+
# (1..2).mean #=> 1.5
|
20
|
+
#
|
21
|
+
def retroactively_include(mod) # :doc:
|
6
22
|
raise TypeError, 'wrong argument type #{mod.class} (expected Module)' unless mod.is_a? Module
|
7
23
|
|
8
24
|
# Although one would expect +A.module_eval("include B")+ to make methods
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|