core_ex 0.4.0 → 0.5.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/ChangeLog +251 -0
  2. data/NEWS +29 -0
  3. data/README +1 -1
  4. data/SPEC.yml +10 -10
  5. data/lib/core_ex/dependencies_ext/constant_load_path.rb +1 -1
  6. data/lib/core_ex/embedded_tests.rb +1 -1
  7. data/lib/core_ex/enumerable.rb +87 -5
  8. data/lib/core_ex/exception.rb +1 -1
  9. data/lib/core_ex/file_utils.rb +1 -1
  10. data/lib/core_ex/lazy_loading.rb +159 -0
  11. data/lib/core_ex/module/attr_once.rb +1 -1
  12. data/lib/core_ex/module/import.rb +4 -6
  13. data/lib/core_ex/module/in_place.rb +1 -1
  14. data/lib/core_ex/module/mix_in_with_args.rb +1 -1
  15. data/lib/core_ex/numeric.rb +46 -0
  16. data/lib/core_ex/object/instance_eval_with_args.rb +1 -1
  17. data/lib/core_ex/object/singleton_class.rb +1 -1
  18. data/lib/core_ex/object/the_first_time.rb +1 -1
  19. data/lib/core_ex/pathname.rb +17 -11
  20. data/lib/core_ex/proc.rb +80 -1
  21. data/lib/core_ex/rakefile_base.rf +192 -296
  22. data/lib/core_ex/require.rb +1 -1
  23. data/lib/core_ex/string.rb +11 -2
  24. data/lib/core_ex/time.rb +1 -1
  25. data/lib/core_ex/try_dup.rb +1 -1
  26. data/lib/core_ex/yaml.rb +101 -79
  27. data/lib/core_ex.rb +129 -128
  28. data/lib/d_time.rb +225 -53
  29. data/lib/dumpable_proc.rb +1 -10
  30. data/lib/path_list.rb +18 -7
  31. data/lib/temp_path.rb +3 -3
  32. data/lib/test/unit/u_i/yaml/test_runner.rb +1 -1
  33. data/lib/version.rb +309 -69
  34. data/lib/yaml_extension.rb +1 -1
  35. data/test/fixtures/lazy_loading/a_b/a/c.rb +6 -0
  36. data/test/fixtures/lazy_loading/a_b/a.rb +2 -0
  37. data/test/fixtures/lazy_loading/a_b/b/c.rb +4 -0
  38. data/test/fixtures/lazy_loading/a_b/b.rb +2 -0
  39. data/test/fixtures/lazy_loading/double/a/bouhou.rb +2 -0
  40. data/test/fixtures/lazy_loading/double/a/foo_bar.rb +5 -0
  41. data/test/fixtures/lazy_loading/double/a/sub/a/suba.rb +7 -0
  42. data/test/fixtures/lazy_loading/double/b/root/sub/b.rb +6 -0
  43. data/test/fixtures/lazy_loading/double/b/root/sub.rb +4 -0
  44. data/test/fixtures/lazy_loading/double/b/root.rb +2 -0
  45. data/test/fixtures/lazy_loading/foo_bars/foo_bar.rb +4 -0
  46. data/test/fixtures/lazy_loading/foo_bars/mods/mod.rb +6 -0
  47. data/test/fixtures/lazy_loading/foo_bars/mods/sub_mod.rb +6 -0
  48. data/test/fixtures/lazy_loading/foo_bars/mods/sub_sub_mod.rb +7 -0
  49. data/test/fixtures/lazy_loading/foo_bars/mods.rb +4 -0
  50. data/test/fixtures/lazy_loading/foo_bars/sub_foo_bar.rb +5 -0
  51. data/test/fixtures/lazy_loading/foo_bars/titis/tutu.rb +6 -0
  52. data/test/fixtures/lazy_loading/foo_bars/totos.rb +6 -0
  53. data/test/fixtures/lazy_loading/foo_bars.rb +4 -0
  54. data/test/lazy_loading/test_already_present_name_absolute.rb +6 -0
  55. data/test/lazy_loading/test_already_present_name_relative.rb +11 -0
  56. data/test/lazy_loading/test_inside_another_module.rb +5 -0
  57. data/test/lazy_loading/test_lazy_loading.rb +179 -0
  58. data/test/sanity/multiple-requires.yml +22 -4
  59. data/test/unit-suite.yml +5 -4
  60. metadata +119 -80
  61. data/SPEC.dyn.yml +0 -10
  62. data/SPEC.gemspec +0 -13
  63. data/test/test-unit-setup.rb +0 -19
  64. /data/test/{resources → fixtures}/require/test_require +0 -0
  65. /data/test/{resources → fixtures}/require/test_require_rb.rb +0 -0
  66. /data/test/{resources → fixtures}/require/test_require_so.so +0 -0
  67. /data/test/{resources → fixtures}/use-from-gems.rb +0 -0
  68. /data/test/{resources → fixtures}/yaml_testrunner/unit_test.rb +0 -0
data/ChangeLog CHANGED
@@ -1,3 +1,254 @@
1
+ 2006-02-23 Nicolas Despr�s <nicolas.despres@gmail.com>
2
+
3
+ Update the NEWS file.
4
+
5
+ * NEWS: Updated for the upcoming release.
6
+
7
+ 2006-02-19 Nicolas Despr�s <nicolas.despres@gmail.com>
8
+
9
+ Remove useless DTime#==.
10
+
11
+ * lib/d_time.rb: Remove useless '==' since '<=>' already do the job.
12
+
13
+ 2006-02-18 Nicolas Pouillard <ertai@lrde.epita.fr>
14
+
15
+ LazyLoading: More tests, and less warnings in sanity.
16
+
17
+ * lib/core_ex/lazy_loading.rb: Hand protect against double inclusion.
18
+
19
+ * test/fixtures/lazy_loading/a_b: New.
20
+ * test/fixtures/lazy_loading/a_b/a: New.
21
+ * test/fixtures/lazy_loading/a_b/a/c.rb: New.
22
+ * test/fixtures/lazy_loading/a_b/b: New.
23
+ * test/fixtures/lazy_loading/a_b/b/c.rb: New.
24
+ * test/fixtures/lazy_loading/a_b/a.rb: New.
25
+ * test/fixtures/lazy_loading/a_b/b.rb: New.
26
+ * test/lazy_loading/test_lazy_loading.rb: Add some tests.
27
+
28
+ 2006-01-09 Nicolas Pouillard <ertai@lrde.epita.fr>
29
+
30
+ Suppress some warnings.
31
+
32
+ * lib/core_ex/lazy_loading.rb: Add an alias.
33
+ * lib/core_ex.rb: Use $VERBOSE directly since silence_warnings is not
34
+ yet available.
35
+
36
+ 2006-01-01 Nicolas Pouillard <ertai@lrde.epita.fr>
37
+
38
+ Extend Inflector::Inflections.
39
+
40
+ * lib/core_ex.rb: Extend Inflector::Inflections to deal with custom
41
+ inflections (e.g. URI -> uri not u_r_i).
42
+ * lib/core_ex/string.rb: Rename import to import! to match with the
43
+ others.
44
+
45
+ 2005-12-31 Nicolas Pouillard <ertai@lrde.epita.fr>
46
+
47
+ LazyLoading: some improvements.
48
+
49
+ * lib/core_ex/lazy_loading.rb: Keep @module at the first place of
50
+ @roots. Avoid duplicatas in selection.
51
+
52
+ 2005-12-31 Nicolas Pouillard <ertai@lrde.epita.fr>
53
+
54
+ Adapt the sanity test.
55
+
56
+ * test/sanity/multiple-requires.yml:
57
+ Add a test that load with require_dependency.
58
+ Update the 2 others.
59
+
60
+ 2005-12-31 Nicolas Pouillard <ertai@lrde.epita.fr>
61
+
62
+ Finish the Dependency/Loading system (I hope so).
63
+
64
+ * test/lazy_loading/test_lazy_loading.rb: Update teardown to
65
+ Dependencies.
66
+ * lib/core_ex/module/import.rb: Remove require_or_load and use
67
+ depend_on.
68
+ * lib/core_ex/lazy_loading.rb: Use require_dependency instead of
69
+ require_or_load.
70
+ * lib/core_ex.rb: Add Dependencies.change_mechanism. Remove became
71
+ useless things about require and verbose.
72
+
73
+ 2005-12-31 Nicolas Pouillard <ertai@lrde.epita.fr>
74
+
75
+ LazyLoading: Fix 2 bugs.
76
+
77
+ * lib/core_ex/lazy_loading.rb: Make empty modules at the very end.
78
+ * lib/core_ex.rb: Remove original_core_ex_require. Handle correctly the
79
+ Dependencies.mechanism to be compliant with Rails and us.
80
+ * test/fixtures/lazy_loading/double/a/sub/a/suba.rb: Remove the p 42.
81
+
82
+ 2005-12-30 Nicolas Pouillard <ertai@lrde.epita.fr>
83
+
84
+ LazyLoading: More tests.
85
+
86
+ * test/lazy_loading/test_lazy_loading.rb: The bouhou_in_double_ab test
87
+ is still failing.
88
+ * lib/core_ex/lazy_loading.rb: Update.
89
+ * test/fixtures/lazy_loading/double: New.
90
+ * test/fixtures/lazy_loading/double/a: New.
91
+ * test/fixtures/lazy_loading/double/a/bouhou.rb: New.
92
+ * test/fixtures/lazy_loading/double/a/foo_bar.rb: New.
93
+ * test/fixtures/lazy_loading/double/a/sub: New.
94
+ * test/fixtures/lazy_loading/double/a/sub/a: New.
95
+ * test/fixtures/lazy_loading/double/a/sub/a/suba.rb: New.
96
+ * test/fixtures/lazy_loading/double/b: New.
97
+ * test/fixtures/lazy_loading/double/b/bouhou: New.
98
+ * test/fixtures/lazy_loading/double/b/root: New.
99
+ * test/fixtures/lazy_loading/double/b/root/sub: New.
100
+ * test/fixtures/lazy_loading/double/b/root/sub/b.rb: New.
101
+ * test/fixtures/lazy_loading/double/b/root/sub.rb: New.
102
+ * test/fixtures/lazy_loading/double/b/root.rb: New.
103
+
104
+ 2005-12-30 Nicolas Pouillard <ertai@lrde.epita.fr>
105
+
106
+ Improving DTime.
107
+
108
+ * lib/d_time.rb: Introdoce TimeUnit's to make it more generic and
109
+ powerful.
110
+
111
+ 2005-12-30 Nicolas Pouillard <ertai@lrde.epita.fr>
112
+
113
+ Minors updates.
114
+
115
+ * lib/core_ex/yaml.rb: Update to recents Yaml versions that have a
116
+ Range support.
117
+ * lib/core_ex/rakefile_base.rf: Require 'version' explicitly.
118
+ * SPEC.yml: Update to the last active_support version.
119
+
120
+ 2005-12-30 Nicolas Pouillard <ertai@lrde.epita.fr>
121
+
122
+ Extend Enumerable.
123
+
124
+ * lib/core_ex/enumerable.rb: Make sum and prod more generic. Add
125
+ average and standard_deviation.
126
+
127
+ 2005-12-30 Nicolas Pouillard <ertai@lrde.epita.fr>
128
+
129
+ CoreEx use LazyLoading.
130
+
131
+ * lib/core_ex.rb: Update dynamic patches and use LazyLoading.
132
+ * lib/core_ex/lazy_loading.rb: Downgrade a little the code to make it
133
+ less CoreEx dependent.
134
+ * lib/core_ex/pathname.rb: Make it less Controllers/Dependencies
135
+ dependent.
136
+
137
+ 2005-12-29 Nicolas Pouillard <ertai@lrde.epita.fr>
138
+
139
+ Add a test to lazy_loading.
140
+
141
+ * test/lazy_loading/test_lazy_loading.rb: Test complex nestings.
142
+
143
+ 2005-12-29 Nicolas Pouillard <ertai@lrde.epita.fr>
144
+
145
+ Add the LazyLoading functionality.
146
+
147
+ * lib/core_ex/lazy_loading.rb: New.
148
+ * test/fixtures/lazy_loading: New.
149
+ * test/fixtures/lazy_loading/foo_bars: New.
150
+ * test/fixtures/lazy_loading/foo_bars/mods: New.
151
+ * test/fixtures/lazy_loading/foo_bars/mods/mod.rb: New.
152
+ * test/fixtures/lazy_loading/foo_bars/mods/sub_sub_mod.rb: New.
153
+ * test/fixtures/lazy_loading/foo_bars/mods/sub_mod.rb: New.
154
+ * test/fixtures/lazy_loading/foo_bars/sub_foo_bar.rb: New.
155
+ * test/fixtures/lazy_loading/foo_bars/mods.rb: New.
156
+ * test/fixtures/lazy_loading/foo_bars/foo_bar.rb: New.
157
+ * test/fixtures/lazy_loading/foo_bars/totos.rb: New.
158
+ * test/fixtures/lazy_loading/foo_bars/titis: New.
159
+ * test/fixtures/lazy_loading/foo_bars/titis/tutu.rb: New.
160
+ * test/fixtures/lazy_loading/foo_bars.rb: New.
161
+ * test/lazy_loading: New.
162
+ * test/lazy_loading/test_already_present_name_absolute.rb: New.
163
+ * test/lazy_loading/test_inside_another_module.rb: New.
164
+ * test/lazy_loading/test_already_present_name_relative.rb: New.
165
+ * test/lazy_loading/test_lazy_loading.rb: New.
166
+
167
+ 2005-12-06 Nicolas Pouillard <ertai@lrde.epita.fr>
168
+
169
+ Some stuffs.
170
+
171
+ * lib/core_ex/enumerable.rb: Add group_by and group_sequences_by.
172
+ * lib/core_ex/rakefile_base.rf: Fix a bug, use Rake::Task.
173
+ * lib/core_ex/yaml.rb: Quote ranges.
174
+ * lib/core_ex/numeric.rb: New. Add !.
175
+ * lib/core_ex.rb: No more load breakpoint, upate an exception.
176
+
177
+ 2005-11-08 Nicolas Pouillard <ertai@lrde.epita.fr>
178
+
179
+ Update to Rake >= 0.6.2.
180
+
181
+ * lib/core_ex/rakefile_base.rf: Task class is now in the Rake module.
182
+
183
+ 2005-11-08 Nicolas Pouillard <ertai@lrde.epita.fr>
184
+
185
+ Update the ActiveSupport dependency.
186
+
187
+ * SPEC.yml: Require ~> 1.2.3.
188
+
189
+ 2005-10-26 Nicolas Pouillard <ertai@lrde.epita.fr>
190
+
191
+ * lib/core_ex/yaml.rb: It reads the IO with each_line and call
192
+ the block with each document.
193
+
194
+ 2005-10-26 Nicolas Pouillard <ertai@lrde.epita.fr>
195
+
196
+ * lib/core_ex/proc.rb: Add instance_call, a magic version of call
197
+ that use instance_eval(_with_args) when arguments are ok for this.
198
+ Add a bunch of unit tests.
199
+
200
+ * lib/dumpable_proc.rb: Remove this silly, because unefficient and
201
+ wrong verification.
202
+ * lib/core_ex/string.rb: Add to_proc, and to_uri.
203
+
204
+ 2005-10-10 Nicolas Pouillard <ertai@lrde.epita.fr>
205
+
206
+ Fix Range#to_yaml_string again.
207
+
208
+ * lib/core_ex/yaml.rb: Dump the given string.
209
+
210
+ 2005-10-09 Nicolas Pouillard <ertai@lrde.epita.fr>
211
+
212
+ Fix Range#to_yaml_string.
213
+
214
+ * lib/core_ex/yaml.rb: Use inspect instead of to_s.
215
+
216
+ 2005-10-09 Nicolas Pouillard <ertai@lrde.epita.fr>
217
+
218
+ Fix 2 unit tests.
219
+
220
+ * lib/temp_path.rb: Adapt tests because object_id can be negative.
221
+ * lib/path_list.rb: Adapt to yaml of ruby 1.8.3.
222
+
223
+ 2005-10-09 Nicolas Pouillard <ertai@lrde.epita.fr>
224
+
225
+ Update uttk-unit options.
226
+
227
+ * test/unit-suite.yml: Use --mode.
228
+
229
+ 2005-10-09 Nicolas Pouillard <ertai@lrde.epita.fr>
230
+
231
+ Update unit tests.
232
+
233
+ * test/unit-suite.yml: Use uttk-unit.
234
+ * lib/core_ex/pathname.rb: Renaming.
235
+ * lib/d_time.rb, lib/core_ex.rb,
236
+ * lib/path_list.rb: Update the Yaml extension.
237
+
238
+ * test/resources: Rename to ...
239
+ * test/fixtures: ... this.
240
+ * test/test-unit-setup.rb: Remove useless since uttk-unit provides the
241
+ same service.
242
+
243
+ 2005-10-09 Nicolas Pouillard <ertai@lrde.epita.fr>
244
+
245
+ Some minor fixes in the base Rakefile.
246
+
247
+ * lib/core_ex/rakefile_base.rf:
248
+ Update the ruby_ex version to ~> 0.3.0.
249
+ Improve error displaying in publish_package.
250
+ Fix a bug with re?vendor_dev.
251
+
1
252
  2005-10-03 Nicolas Pouillard <ertai@lrde.epita.fr>
2
253
 
3
254
  Bump to 0.4.
data/NEWS CHANGED
@@ -1,3 +1,32 @@
1
+ = New in 0.5, 2006-02-24:
2
+
3
+ This release makes CoreEx compatible with ruby 1.8.4!
4
+
5
+ Backward compatibility with older version of Ruby is no longer maintained.
6
+
7
+ * LazyLoading:
8
+ Load Ruby files lazily.
9
+ For example Foo::BarBaz::Test.new will require 'foo/bar_baz/test'.
10
+
11
+ * DTime:
12
+ Is now Comparable and supports some arithmetic operators.
13
+
14
+ * Version:
15
+ Re-design to integrate a better release concept.
16
+ It supports complex release evolutions and a good comparison between
17
+ them.
18
+ e.g: dev-ruby/core_ex-0.5_alpha1 < dev-ruby/core_ex-0.5_p4
19
+ core_ex-0.5_rc == core_ex-0.5_beta4.release_candidate
20
+
21
+ * Yaml:
22
+ Update the Yaml extension, add YAML.load_from_io, YAML.have_option? and
23
+ YAML::BaseNode.symbol_safe_key_transform which is complex symbol aware
24
+ (:"a complex symbol").
25
+
26
+ * Numeric#fact:
27
+ Extend the Numeric module with a factorial method (alias _!, e.g: 42._!).
28
+
29
+
1
30
  = New in 0.4, 2005-10-03:
2
31
 
3
32
  This release is mainly a bugfix release compatible with ruby 1.8.3!
data/README CHANGED
@@ -1,4 +1,4 @@
1
- CoreEx is designed to provides a simple but quite useful extension of the
1
+ CoreEx is designed to provide a simple but quite useful extension of the
2
2
  standard library of Ruby. Thus some classes and modules like Pathname,
3
3
  Enumerable, Exception, FileUtils, String, YAML, Module, Class and Object are
4
4
  extended. There are also some new features like DTime, TempPath, Version,
data/SPEC.yml CHANGED
@@ -1,29 +1,29 @@
1
1
  ---
2
- Author: The TTK Team.
2
+ Author: The Uttk Team.
3
3
  License: Ruby License
4
- Revision: '$Id$'
4
+ Revision: '$Id: /w/fey/ruby_ex/trunk/core_ex/SPEC.yml 22200 2006-02-23T23:21:04.354576Z pouillar $'
5
5
 
6
- name: core_ex
6
+ version: !feydakins.org,2006/version dev-ruby/core_ex-0.5_alpha1
7
7
 
8
8
  title: CoreEx -- A proposal for a standard library extension.
9
9
  summary: CoreEx is a proposal for a standard library extension.
10
10
  description: >
11
- CoreEx is designed to provides a simple but quite useful extension of the
11
+ CoreEx is designed to provide a simple but quite useful extension of the
12
12
  standard library of Ruby. So some classes and modules like Pathname, Time,
13
13
  Enumerable, Exception, FileUtils, String, and YAML are extended. There is
14
14
  also some new features like attr_once, DTime, TempPath, Version,
15
15
  embedded_tests, filelist (almost from rake), a common Rakefile, and an
16
16
  extension of the require system.
17
17
  homepage: http://api.feydakins.org/core_ex
18
+
19
+ user: ertai
18
20
  rubyforge_project: ttk
19
21
  rubyforge_sub_package_name: core_ex
20
-
21
22
  root_test_suite: test/check-pkg-core_ex.yml
22
23
  rdoc_dir: doc/html
24
+ trunk_url: svn://svn.feydakins.org/ruby_ex/trunk/core_ex
23
25
  tags_url: svn://svn.feydakins.org/ruby_ex/tags
24
26
 
25
- commit_command: ci
26
-
27
27
  rdoc_files: !filelist
28
28
  - README
29
29
  - AUTHORS
@@ -37,7 +37,7 @@ pkg_files: !filelist
37
37
 
38
38
  dependencies:
39
39
  activesupport:
40
- gem: ~> 1.1.1
41
- tarball: 5161/activesupport-1.1.1.tgz
40
+ gem: ~> 1.2.5
41
+ tarball: 7638/activesupport-1.2.5.tgz
42
42
 
43
- ttk_version: ~> 0.3.0
43
+ uttk_version: ~> 0.3.1
@@ -1,7 +1,7 @@
1
1
  # Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
2
2
  # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
3
3
  # License:: Gnu General Public License.
4
- # Revision:: $Id: constant_load_path.rb 336 2005-09-06 20:32:49Z ertai $
4
+ # Revision:: $Id: /w/fey/ruby_ex/trunk/core_ex/lib/core_ex/dependencies_ext/constant_load_path.rb 7941 2005-09-06T20:32:49.915023Z ertai $
5
5
 
6
6
  module CoreEx
7
7
 
@@ -1,7 +1,7 @@
1
1
  # Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
2
2
  # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
3
3
  # License:: Gnu General Public License.
4
- # Revision:: $Id: embedded_tests.rb 345 2005-09-09 01:40:37Z ertai $
4
+ # Revision:: $Id: /w/fey/ruby_ex/trunk/core_ex/lib/core_ex/embedded_tests.rb 7950 2005-09-09T01:40:37.050549Z ertai $
5
5
 
6
6
 
7
7
  module CoreEx
@@ -1,7 +1,7 @@
1
1
  # Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
2
2
  # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
3
3
  # License:: Gnu General Public License.
4
- # Revision:: $Id: enumerable.rb 334 2005-09-04 14:29:40Z ertai $
4
+ # Revision:: $Id: /w/fey/ruby_ex/trunk/core_ex/lib/core_ex/enumerable.rb 8033 2005-12-30T02:37:15.335624Z ertai $
5
5
 
6
6
 
7
7
  module CoreEx
@@ -28,13 +28,27 @@ module Enumerable
28
28
  end
29
29
 
30
30
 
31
- def sum
32
- fold(0) { |accu, x| accu + x }
31
+ def sum ( init=0 )
32
+ inject(init) { |accu, x| accu + x }
33
33
  end
34
34
 
35
35
 
36
- def prod
37
- fold(1) { |accu, x| accu * x }
36
+ def prod ( init=1 )
37
+ inject(init) { |accu, x| accu * x }
38
+ end
39
+
40
+
41
+ def average ( init=0 )
42
+ size_ = size.to_f
43
+ inject(init) { |accu, x| accu + x / size_ }
44
+ end
45
+
46
+
47
+ # fr: ecart type
48
+ def standard_deviation ( init=0, average_=average(init) )
49
+ size_ = size.to_f
50
+ sigma = inject(init) { |accu, x| accu + ((x - average_) ** 2) / size_ }
51
+ Math.sqrt sigma
38
52
  end
39
53
 
40
54
 
@@ -51,6 +65,40 @@ module Enumerable
51
65
  end
52
66
  end
53
67
 
68
+ def group_by ( &block )
69
+ result = []
70
+ sorted = sort_by(&block)
71
+ current = nil
72
+ sorted.each do |x|
73
+ new_val = block[x]
74
+ if current != new_val
75
+ result << [x]
76
+ current = new_val
77
+ else
78
+ result.last << x
79
+ end
80
+ end
81
+ result
82
+ end
83
+
84
+ def group_sequences_by ( &block )
85
+ result = []
86
+ current = nil
87
+ each do |x|
88
+ if current.nil?
89
+ result << [x]
90
+ else
91
+ if block[current, x]
92
+ result.last << x
93
+ else
94
+ result << [x]
95
+ end
96
+ end
97
+ current = x
98
+ end
99
+ result
100
+ end
101
+
54
102
  end # module Enumerable
55
103
 
56
104
 
@@ -128,6 +176,20 @@ test_section __FILE__ do
128
176
  assert_equal(3628800, @h.keys.prod)
129
177
  end
130
178
 
179
+ def test_average
180
+ assert_equal 10, [0, 20].average
181
+ assert_equal 10, [10, 10].average
182
+ assert_equal 10, [0, 10, 20].average
183
+ assert_equal '2.0', [2, 2, 2, 3, 1, 4, 0].average.to_s
184
+ end
185
+
186
+ def test_standard_deviation
187
+ assert_equal 10, [0, 20].standard_deviation
188
+ assert_equal 0, [10, 10].standard_deviation
189
+ assert_equal '8.16496580927726', [0, 10, 20].standard_deviation.to_s
190
+ assert_equal '1.19522860933439', [2, 2, 2, 3, 1, 4, 0].standard_deviation.to_s
191
+ end
192
+
131
193
  def each_pair_checker ( enum, ref )
132
194
  j = 0
133
195
  enum.each_pair do |i, x|
@@ -159,6 +221,26 @@ test_section __FILE__ do
159
221
  assert_equal(a.flatten.sum, y)
160
222
  end
161
223
 
224
+ def test_group_by
225
+ foo31 = { :name => 'foo', :age => 31 }
226
+ foo2 = { :name => 'foo', :age => 2 }
227
+ bar2 = { :name => 'bar', :age => 2 }
228
+ bar4 = { :name => 'bar', :age => 4 }
229
+ bar6 = { :name => 'bar', :age => 6 }
230
+ baz7 = { :name => 'baz', :age => 7 }
231
+ list = [foo31, bar2, foo2, bar4, bar6, baz7]
232
+ groups = list.group_by { |x| x[:name] }
233
+ assert_equal [[bar4, bar2, bar6], [baz7], [foo2, foo31]], groups, 'name'
234
+ groups = list.group_by { |x| x[:age] }
235
+ assert_equal [[foo2, bar2], [bar4], [bar6], [baz7], [foo31]], groups, 'age'
236
+ end
237
+
238
+ def test_group_sequences_by
239
+ list = [1, 2, 3, 4, 5, 8, 9, 3, 4, 5, 2, 1, 3, 4, 5]
240
+ seqs = list.group_sequences_by { |x, y| y - x == 1 }
241
+ assert_equal [[1, 2, 3, 4, 5], [8, 9], [3, 4, 5], [2], [1],
242
+ [3, 4, 5]], seqs
243
+ end
162
244
 
163
245
  end # EnumerableTest
164
246
 
@@ -1,7 +1,7 @@
1
1
  # Copyright:: Copyright (c) 2004 Nicolas Despres. All rights reserved.
2
2
  # Author:: Nicolas Despres <polrop@lrde.epita.fr>.
3
3
  # License:: Gnu General Public License.
4
- # Revision:: $Id: exception.rb 334 2005-09-04 14:29:40Z ertai $
4
+ # Revision:: $Id: /w/fey/ruby_ex/trunk/core_ex/lib/core_ex/exception.rb 7939 2005-09-04T14:29:40.923141Z ertai $
5
5
 
6
6
  module CoreEx
7
7
 
@@ -1,7 +1,7 @@
1
1
  # Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
2
2
  # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
3
3
  # License:: Gnu General Public License.
4
- # Revision:: $Id: file_utils.rb 334 2005-09-04 14:29:40Z ertai $
4
+ # Revision:: $Id: /w/fey/ruby_ex/trunk/core_ex/lib/core_ex/file_utils.rb 7939 2005-09-04T14:29:40.923141Z ertai $
5
5
 
6
6
 
7
7
  module CoreEx
@@ -0,0 +1,159 @@
1
+ # Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
2
+ # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
3
+ # License:: Gnu General Public License.
4
+ # Revision:: $Id: /w/fey/ruby_ex/trunk/core_ex/lib/core_ex/lazy_loading.rb 21865 2006-02-18T17:13:28.680350Z pouillar $
5
+
6
+ # This file is hand protected against double inclusion for stranges reasons
7
+ unless defined? LazyLoading
8
+
9
+ require 'active_support/binding_of_caller'
10
+
11
+
12
+ module LazyLoading
13
+
14
+ mattr_accessor :logger
15
+ self.logger = Logger.new(STDERR)
16
+
17
+ class LazyLoader
18
+
19
+ mattr_accessor :logger
20
+ self.logger = LazyLoading.logger
21
+
22
+ def initialize ( aModule, aConst, theNesting )
23
+ @const = aConst
24
+ @roots = theNesting
25
+ @module = aModule
26
+
27
+ # self is not necessary in the nesting:
28
+ # class B
29
+ # end
30
+ #
31
+ # class A
32
+ # p B::C # here the nesting is [A] and self is B
33
+ # end
34
+ @roots.delete aModule
35
+ @roots.unshift aModule
36
+
37
+ # The Object root is here to deal with top level objects:
38
+ # class B
39
+ # end
40
+ #
41
+ # class A
42
+ # p B
43
+ # end
44
+ @roots << Object unless @roots.include? Object
45
+
46
+ @selection = []
47
+ end
48
+
49
+ attr_reader :const, :roots, :root, :selection, :basename
50
+
51
+ # For each `roots' module load all files that match.
52
+ def load
53
+ roots.each do |@root|
54
+ setup_basename!
55
+ select!
56
+ unless selection.empty?
57
+ import_the_selection!
58
+ if root.const_defined? const
59
+ logger.debug { "LazyLoader#load: Ok `#{const}' defined" }
60
+ succeeded!
61
+ return result
62
+ end
63
+ logger.debug { "LazyLoader#load: Even after loading #{selection.inspect}, #{const} is not available (root: #{root})" }
64
+ end
65
+ end
66
+ roots.each do |@root|
67
+ setup_basename!
68
+ make_a_new_module_if_the_directory_exist!
69
+ return result if succeeded?
70
+ end
71
+ return result
72
+ end
73
+
74
+ def setup_basename!
75
+ prefix = (root == Object)? '' : "#{root}::"
76
+ @basename = "#{prefix}#{const}".underscore
77
+ end
78
+
79
+ def select!
80
+ each_load_path do |dir|
81
+ %w[ rb rf so ].each do |ext|
82
+ path = Pathname.new(dir) + "#{basename}.#{ext}"
83
+ selection << basename if path.exist? and not selection.include? basename
84
+ end
85
+ end
86
+ logger.debug { "LazyLoader#select!(basename: #{basename}): #{selection.inspect}" }
87
+ end
88
+
89
+ def make_a_new_module_if_the_directory_exist!
90
+ each_load_path do |dir|
91
+ path = Pathname.new(dir) + basename
92
+ if path.directory?
93
+ mod = "#{root.name}::#{const}".sub(/^:*/, '::')
94
+ logger.debug do
95
+ "LazyLoader#make_a_new_module_if_the_directory_exist!: " +
96
+ "Build #{mod}"
97
+ end
98
+ eval "module #{mod} end"
99
+ succeeded!
100
+ end
101
+ end
102
+ end
103
+
104
+ def import_the_selection!
105
+ selection.each { |path| require_dependency path }
106
+ end
107
+
108
+ def succeeded!
109
+ @result = root.const_get const
110
+ end
111
+
112
+ def succeeded?
113
+ defined? @result
114
+ end
115
+
116
+ def result
117
+ if succeeded?
118
+ return @result
119
+ else
120
+ return @module.original_core_ex_const_missing(const)
121
+ end
122
+ end
123
+
124
+ def each_load_path ( &block )
125
+ $LOAD_PATH.each(&block)
126
+ end
127
+
128
+ end # class LazyLoader
129
+
130
+ class << self
131
+ def load ( aModule, aConst, theNesting )
132
+ logger.info { "LazyLoading::load(module: #{aModule}, const: #{aConst}, nesting: #{theNesting.inspect})" }
133
+ LazyLoader.new(aModule, aConst, theNesting).load
134
+ end
135
+ end
136
+
137
+ end # module LazyLoading
138
+
139
+ LazyLoading.logger.level = Logger::WARN
140
+
141
+ class Module
142
+ def name
143
+ the_standard_name.sub(/^Controllers::/, '')
144
+ end
145
+ alias_method :core_ex_const_missing, :const_missing
146
+ def const_missing ( aConst )
147
+ Binding.of_caller do |binding|
148
+ nesting = eval "::Module.nesting", binding
149
+ return LazyLoading.load(self, aConst, nesting)
150
+ end
151
+ # Nothing here, not reached !!!
152
+ end
153
+ end
154
+
155
+ test_section __FILE__ do
156
+ load CoreEx.test_dir/'lazy_loading'/'test_lazy_loading.rb'
157
+ end
158
+
159
+ end
@@ -1,7 +1,7 @@
1
1
  # Copyright:: Copyright (c) 2004 Nicolas Despres. All rights reserved.
2
2
  # Author:: Nicolas Despres <polrop@lrde.epita.fr>.
3
3
  # License:: Gnu General Public License.
4
- # Revision:: $Id: attr_once.rb 333 2005-09-04 14:17:17Z ertai $
4
+ # Revision:: $Id: /w/fey/ruby_ex/trunk/core_ex/lib/core_ex/module/attr_once.rb 7938 2005-09-04T14:17:17.570028Z ertai $
5
5
 
6
6
 
7
7
  module CoreEx