facets 2.9.0.pre.2 → 2.9.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/HISTORY.rdoc +1 -0
- data/lib/core/facets/array/recurse.rb +1 -1
- data/lib/core/facets/hash/recurse.rb +1 -1
- data/lib/tour/facets/kernel/y.rb +17 -0
- data/lib/tour/facets/module/prepend.rb +6 -0
- data/meta/data.rb +4 -4
- data/meta/{gemfile → package} +2 -2
- data/test/core/array/test_recurse.rb +15 -0
- data/test/core/hash/test_recurse.rb +13 -0
- data/test/tour/module/test_preextend.rb +22 -0
- data/test/tour/module/test_prepend.rb +3 -5
- metadata +12 -13
data/HISTORY.rdoc
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
module Kernel
|
2
|
+
|
3
|
+
# Y-combinator.
|
4
|
+
#
|
5
|
+
# f = Y do |n, acc, &b|
|
6
|
+
# n < 2 ? acc : b.(n-1, n * acc)
|
7
|
+
# end
|
8
|
+
#
|
9
|
+
# f.call(5, 1) #=> 120
|
10
|
+
#
|
11
|
+
# CREDIT: Michael Fellinger
|
12
|
+
|
13
|
+
def Y(*args, &block)
|
14
|
+
y = lambda{|*args| block.call(*args, &y) }
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -43,6 +43,12 @@ class Module
|
|
43
43
|
#
|
44
44
|
# X.new.a #=> MXa
|
45
45
|
#
|
46
|
+
# IMPORTANT! #prepend is not dynamic, rather it copies all methods
|
47
|
+
# when included on a class or module. For this reason one must be careful
|
48
|
+
# to invoke #prepend AFTER any method definitions that are to be effected.
|
49
|
+
# Ideally this would not be necessary, but it would require support in
|
50
|
+
# Ruby's C+ source to make it possible.
|
51
|
+
|
46
52
|
def prepend(mod)
|
47
53
|
include Prependable
|
48
54
|
include mod
|
data/meta/data.rb
CHANGED
@@ -6,10 +6,10 @@ module Facets
|
|
6
6
|
File.dirname(__FILE__)
|
7
7
|
end
|
8
8
|
|
9
|
-
def self.
|
10
|
-
@
|
9
|
+
def self.package
|
10
|
+
@package ||= (
|
11
11
|
require 'yaml'
|
12
|
-
YAML.load(File.new(__DIR__ + '/
|
12
|
+
YAML.load(File.new(__DIR__ + '/package'))
|
13
13
|
)
|
14
14
|
end
|
15
15
|
|
@@ -22,7 +22,7 @@ module Facets
|
|
22
22
|
|
23
23
|
def self.const_missing(name)
|
24
24
|
key = name.to_s.downcase
|
25
|
-
|
25
|
+
package[key] || profile[key] || super(name)
|
26
26
|
end
|
27
27
|
|
28
28
|
end
|
data/meta/{gemfile → package}
RENAMED
@@ -14,4 +14,19 @@ testcase Array do
|
|
14
14
|
a.assert ["a", ["b", "c"]]
|
15
15
|
end
|
16
16
|
|
17
|
+
unit :recurse => "with Hashes" do
|
18
|
+
require 'facets/hash/recurse'
|
19
|
+
objects = []
|
20
|
+
struct = [1, 2, {:a => 3, :b => [4, 5, {:c=>6}]}, [7, 8]]
|
21
|
+
struct.recurse(Array, Hash){|o| objects << o; o }
|
22
|
+
|
23
|
+
objects.assert.include?( [7, 8] )
|
24
|
+
objects.assert.include?( {:c=>6} )
|
25
|
+
objects.assert.include?( [4, 5, {:c=>6}] )
|
26
|
+
objects.assert.include?( {:a => 3, :b => [4, 5, {:c=>6}]} )
|
27
|
+
objects.assert.include?( struct )
|
28
|
+
|
29
|
+
objects.length.assert == 5
|
30
|
+
end
|
31
|
+
|
17
32
|
end
|
@@ -14,5 +14,18 @@ testcase Hash do
|
|
14
14
|
h.assert == {"a"=>1, "b"=>{"b1"=>1, "b2"=>2}}
|
15
15
|
end
|
16
16
|
|
17
|
+
unit :recurse => "with Arrays" do
|
18
|
+
require 'facets/array/recurse'
|
19
|
+
objects = []
|
20
|
+
struct = {:a => 3, :b => [4, 5, {:c=>6}]}
|
21
|
+
struct.recurse(Array, Hash){|o| objects << o; o }
|
22
|
+
|
23
|
+
objects.assert.include?( {:c=>6} )
|
24
|
+
objects.assert.include?( [4, 5, {:c=>6}] )
|
25
|
+
objects.assert.include?( struct )
|
26
|
+
|
27
|
+
objects.length.assert == 3
|
28
|
+
end
|
29
|
+
|
17
30
|
end
|
18
31
|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
covers 'facets/module/preextend'
|
2
|
+
|
3
|
+
tests Module do
|
4
|
+
|
5
|
+
unit :preextend => "module method" do
|
6
|
+
m = Module.new do
|
7
|
+
def q; "qm"; end
|
8
|
+
end
|
9
|
+
|
10
|
+
n = Module.new do
|
11
|
+
preextend m
|
12
|
+
def q; "qn"; end
|
13
|
+
end
|
14
|
+
|
15
|
+
x = Class.new do
|
16
|
+
include n
|
17
|
+
end
|
18
|
+
|
19
|
+
n.q.assert == "qm"
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -2,23 +2,21 @@ covers 'facets/module/prepend'
|
|
2
2
|
|
3
3
|
tests Module do
|
4
4
|
|
5
|
-
unit :prepend
|
5
|
+
unit :prepend do
|
6
6
|
m = Module.new do
|
7
7
|
def q; "qm"; end
|
8
8
|
end
|
9
9
|
|
10
10
|
n = Module.new do
|
11
|
-
prepend m
|
12
11
|
def q; "qn"; end
|
12
|
+
prepend m
|
13
13
|
end
|
14
14
|
|
15
15
|
x = Class.new do
|
16
16
|
include n
|
17
17
|
end
|
18
18
|
|
19
|
-
|
19
|
+
x.new.q.assert == "qm"
|
20
20
|
end
|
21
21
|
|
22
|
-
# Wish this worked.
|
23
|
-
# x.new.q.assert == "qm"
|
24
22
|
end
|
metadata
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: facets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 43
|
5
|
+
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 9
|
9
9
|
- 0
|
10
|
-
|
11
|
-
- 2
|
12
|
-
version: 2.9.0.pre.2
|
10
|
+
version: 2.9.0
|
13
11
|
platform: ruby
|
14
12
|
authors:
|
15
13
|
- Thomas Sawyer <transfire@gmail.com>
|
@@ -17,7 +15,7 @@ autorequire:
|
|
17
15
|
bindir: bin
|
18
16
|
cert_chain: []
|
19
17
|
|
20
|
-
date: 2010-
|
18
|
+
date: 2010-10-12 00:00:00 -04:00
|
21
19
|
default_executable:
|
22
20
|
dependencies:
|
23
21
|
- !ruby/object:Gem::Dependency
|
@@ -634,6 +632,7 @@ files:
|
|
634
632
|
- lib/tour/facets/kernel/instance_exec.rb
|
635
633
|
- lib/tour/facets/kernel/memo.rb
|
636
634
|
- lib/tour/facets/kernel/trap_chain.rb
|
635
|
+
- lib/tour/facets/kernel/y.rb
|
637
636
|
- lib/tour/facets/method/memoize.rb
|
638
637
|
- lib/tour/facets/module/attr_class_accessor.rb
|
639
638
|
- lib/tour/facets/module/attr_inheritor.rb
|
@@ -657,7 +656,7 @@ files:
|
|
657
656
|
- lib/tour/facets/string/crypt.rb
|
658
657
|
- lib/tour/facets/string/roman.rb
|
659
658
|
- meta/data.rb
|
660
|
-
- meta/
|
659
|
+
- meta/package
|
661
660
|
- meta/profile
|
662
661
|
- qed/applique/file_helpers.rb
|
663
662
|
- qed/core/array/combination.rdoc
|
@@ -1145,6 +1144,7 @@ files:
|
|
1145
1144
|
- test/tour/module/test_memoize.rb
|
1146
1145
|
- test/tour/module/test_method_space.rb
|
1147
1146
|
- test/tour/module/test_module_load.rb
|
1147
|
+
- test/tour/module/test_preextend.rb
|
1148
1148
|
- test/tour/module/test_prepend.rb
|
1149
1149
|
- Rakefile
|
1150
1150
|
- HISTORY.rdoc
|
@@ -1178,14 +1178,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
1178
1178
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
1179
1179
|
none: false
|
1180
1180
|
requirements:
|
1181
|
-
- - "
|
1181
|
+
- - ">="
|
1182
1182
|
- !ruby/object:Gem::Version
|
1183
|
-
hash:
|
1183
|
+
hash: 3
|
1184
1184
|
segments:
|
1185
|
-
-
|
1186
|
-
|
1187
|
-
- 1
|
1188
|
-
version: 1.3.1
|
1185
|
+
- 0
|
1186
|
+
version: "0"
|
1189
1187
|
requirements: []
|
1190
1188
|
|
1191
1189
|
rubyforge_project: facets
|
@@ -1577,4 +1575,5 @@ test_files:
|
|
1577
1575
|
- test/tour/module/test_memoize.rb
|
1578
1576
|
- test/tour/module/test_method_space.rb
|
1579
1577
|
- test/tour/module/test_module_load.rb
|
1578
|
+
- test/tour/module/test_preextend.rb
|
1580
1579
|
- test/tour/module/test_prepend.rb
|