facets 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. data/AUTHORS +3 -3
  2. data/README +6 -7
  3. data/lib/core/facets.rb +1 -46
  4. data/lib/core/facets/array.rb +3 -0
  5. data/lib/core/facets/array/indexable.rb +6 -1
  6. data/lib/core/facets/array/only.rb +20 -0
  7. data/lib/core/facets/dir/multiglob.rb +12 -1
  8. data/lib/core/facets/enumerable.rb +0 -1
  9. data/lib/core/facets/enumerable/collect.rb +1 -0
  10. data/lib/core/facets/enumerable/combination.rb +44 -90
  11. data/lib/core/facets/facets.rb +46 -0
  12. data/lib/core/facets/file/write.rb +46 -58
  13. data/lib/core/facets/hash.rb +2 -0
  14. data/lib/core/facets/hash/select.rb +14 -0
  15. data/lib/core/facets/integer/multiples.rb +12 -55
  16. data/lib/core/facets/kernel/val.rb +14 -0
  17. data/lib/core/facets/module/alias.rb +28 -9
  18. data/lib/core/facets/module/methods.rb +18 -0
  19. data/lib/core/facets/module/traits.rb +65 -70
  20. data/lib/core/facets/proc/compose.rb +15 -12
  21. data/lib/core/facets/stackable.rb +3 -2
  22. data/lib/core/facets/string/format.rb +4 -6
  23. data/lib/core/facets/string/tabs.rb +34 -0
  24. data/lib/core/facets/symbol.rb +1 -0
  25. data/lib/core/facets/symbol/succ.rb +1 -42
  26. data/lib/core/facets/symbol/to_proc.rb +34 -0
  27. data/lib/methods/facets/array/contains.rb +1 -0
  28. data/lib/methods/facets/facets/require_core.rb +1 -0
  29. data/lib/methods/facets/file/writelines.rb +1 -0
  30. data/lib/methods/facets/io/writelines.rb +1 -0
  31. data/lib/methods/facets/kernel/not_nil.rb +1 -0
  32. data/lib/methods/facets/module/conflict.rb +1 -0
  33. data/lib/methods/facets/module/instance_method_defined.rb +1 -0
  34. data/lib/methods/facets/module/module_method_defined.rb +1 -0
  35. data/lib/methods/facets/module/private_conflict.rb +1 -0
  36. data/lib/methods/facets/module/protected_conflict.rb +1 -0
  37. data/lib/methods/facets/module/public_conflict.rb +1 -0
  38. data/lib/methods/facets/string/expand_tabs.rb +1 -0
  39. data/lib/methods/facets/string/outdent.rb +1 -0
  40. data/lib/methods/facets/string/taballto.rb +1 -0
  41. data/lib/more/facets/arguments.rb +1 -1
  42. data/lib/more/facets/association.rb +0 -46
  43. data/lib/more/facets/autoarray.rb +0 -28
  44. data/lib/more/facets/command.rb +341 -8
  45. data/lib/more/facets/dictionary.rb +25 -131
  46. data/lib/more/facets/downloader.rb +1 -1
  47. data/lib/more/facets/infinity.rb +3 -3
  48. data/lib/more/facets/interval.rb +0 -161
  49. data/lib/more/facets/multiton.rb +16 -12
  50. data/lib/more/facets/namespace.rb +1 -1
  51. data/lib/more/facets/ostruct.rb +46 -10
  52. data/lib/more/facets/overload.rb +0 -51
  53. data/lib/more/facets/paramix.rb +0 -97
  54. data/lib/more/facets/pp_s.rb +30 -0
  55. data/lib/more/facets/progressbar.rb +18 -10
  56. data/lib/more/facets/prototype.rb +1 -40
  57. data/lib/more/facets/random.rb +1 -0
  58. data/lib/more/facets/rbsystem.rb +4 -1
  59. data/lib/more/facets/snapshot.rb +8 -1
  60. data/lib/more/facets/stylize.rb +2 -0
  61. data/meta/{project.yaml → facets-2.0.3.roll} +22 -14
  62. data/meta/manifest.txt +38 -8
  63. data/task/{config.yaml → config/general.yaml} +7 -2
  64. data/task/{rdoc.yaml → config/rdoc.yaml} +1 -1
  65. data/task/crosstest +309 -0
  66. data/task/isotest +293 -0
  67. data/task/loadtest +28 -0
  68. data/task/methods +4 -4
  69. data/task/prepare +5 -0
  70. data/task/publish +2 -2
  71. data/task/rdoc +1 -0
  72. data/task/syntax +29 -0
  73. data/task/test +0 -1
  74. data/task/testeach +42 -0
  75. data/task/testpairs +50 -0
  76. data/test/lib/rq.rb +15 -0
  77. data/test/unit/array/test_merge.rb +21 -43
  78. data/test/unit/array/test_only.rb +21 -0
  79. data/test/unit/enumerable/test_collect.rb +1 -21
  80. data/test/unit/enumerable/test_combination.rb +50 -44
  81. data/test/unit/file/test_topath.rb +48 -57
  82. data/test/unit/file/test_write.rb +82 -0
  83. data/test/unit/hash/test_select.rb +43 -0
  84. data/test/unit/integer/test_multiples.rb +28 -32
  85. data/test/unit/kernel/test_report.rb +9 -12
  86. data/test/unit/kernel/test_val.rb +50 -45
  87. data/test/unit/module/test_include.rb +56 -57
  88. data/test/unit/module/test_name.rb +42 -55
  89. data/test/unit/module/test_traits.rb +46 -47
  90. data/test/unit/string/test_filter.rb +19 -34
  91. data/test/unit/string/test_format.rb +87 -96
  92. data/test/unit/string/test_regesc.rb +18 -26
  93. data/test/unit/string/test_tabs.rb +226 -119
  94. data/test/unit/symbol/test_succ.rb +14 -23
  95. data/test/unit/symbol/test_to_proc.rb +41 -0
  96. data/test/unit/test_association.rb +38 -47
  97. data/test/unit/test_attributes.rb +24 -33
  98. data/test/unit/test_autoarray.rb +23 -32
  99. data/test/unit/test_command.rb +26 -0
  100. data/test/unit/test_dictionary.rb +123 -117
  101. data/test/unit/test_infinity.rb +41 -47
  102. data/test/unit/test_inheritor.rb +133 -142
  103. data/test/unit/test_interval.rb +129 -93
  104. data/test/unit/test_ostruct.rb +148 -101
  105. data/test/unit/test_overload.rb +8 -15
  106. data/test/unit/test_paramix.rb +67 -73
  107. data/test/unit/test_pp_s.rb +23 -0
  108. data/test/unit/test_prototype.rb +28 -38
  109. metadata +47 -11
  110. data/lib/core/facets/enumerable/instance_map.rb +0 -0
  111. data/lib/more/facets/command_options.rb +0 -328
  112. data/meta/version.txt +0 -1
  113. data/task/load +0 -39
  114. data/test/unit/test_command_options.rb +0 -29
@@ -27,7 +27,12 @@
27
27
  # FOR A PARTICULAR PURPOSE.
28
28
  #
29
29
  # Originally ported from OrderHash 2.0, Copyright (c) 2005 jan molic
30
-
30
+ #
31
+ # LOG:
32
+ #
33
+ # - 2007.10.31 trans
34
+ # Fixed initialize so the constructor blocks correctly effected dictionary
35
+ # rather then just the internal hash.
31
36
 
32
37
  # = Dictionary
33
38
  #
@@ -81,7 +86,7 @@ class Dictionary
81
86
  # TODO is this needed? Doesn't the super class do this?
82
87
  #++
83
88
 
84
- def []( *args )
89
+ def [](*args)
85
90
  hsh = new
86
91
  if Hash === args[0]
87
92
  hsh.replace(args[0])
@@ -97,7 +102,7 @@ class Dictionary
97
102
 
98
103
  # Like #new but the block sets the order.
99
104
  #
100
- def new_by( *args, &blk )
105
+ def new_by(*args, &blk)
101
106
  new(*args).order_by(&blk)
102
107
  end
103
108
 
@@ -113,8 +118,8 @@ class Dictionary
113
118
  #
114
119
  # Dictionary.new.order_by { |key,value| key }
115
120
 
116
- def alpha( *args, &block )
117
- new( *args, &block ).order_by_key
121
+ def alpha(*args, &block)
122
+ new(*args, &block).order_by_key
118
123
  end
119
124
 
120
125
  # Alternate to #new which auto-creates sub-dictionaries as needed.
@@ -122,17 +127,21 @@ class Dictionary
122
127
  # d = Dictionary.auto
123
128
  # d["a"]["b"]["c"] = "abc" #=> { "a"=>{"b"=>{"c"=>"abc"}}}
124
129
  #
125
- def auto( *args )
130
+ def auto(*args)
126
131
  #AutoDictionary.new(*args)
127
- leet = lambda { |hsh, key| hsh[key] = new( &leet ) }
132
+ leet = lambda { |hsh, key| hsh[key] = new(&leet) }
128
133
  new(*args, &leet)
129
134
  end
130
135
  end
131
136
 
132
- def initialize( *args, &blk )
137
+ # New Dictiionary.
138
+
139
+ def initialize(*args, &blk)
133
140
  @order = []
134
141
  @order_by = nil
135
- @hash = Hash.new( *args, &blk )
142
+ dict = self # This ensure autmatic key entry effect the
143
+ oblk = lambda{ |hsh, key| blk[dict,key] } # dictionary rather then just the interal hash.
144
+ @hash = Hash.new(*args, &oblk)
136
145
  end
137
146
 
138
147
  def order
@@ -190,7 +199,7 @@ class Dictionary
190
199
 
191
200
  def reorder
192
201
  if @order_by
193
- assoc = @order.collect{ |k| [k,@hash[k]] }.sort_by( &@order_by )
202
+ assoc = @order.collect{ |k| [k,@hash[k]] }.sort_by(&@order_by)
194
203
  @order = assoc.collect{ |k,v| k }
195
204
  end
196
205
  @order
@@ -201,7 +210,7 @@ class Dictionary
201
210
  # super hsh2
202
211
  #end
203
212
 
204
- def ==( hsh2 )
213
+ def ==(hsh2)
205
214
  if hsh2.is_a?( Dictionary )
206
215
  @order == hsh2.order &&
207
216
  @hash == hsh2.instance_variable_get("@hash")
@@ -214,8 +223,8 @@ class Dictionary
214
223
  @hash[ k ]
215
224
  end
216
225
 
217
- def fetch( k, *a, &b )
218
- @hash.fetch( k, *a, &b )
226
+ def fetch(k, *a, &b)
227
+ @hash.fetch(k, *a, &b)
219
228
  end
220
229
 
221
230
  # Store operator.
@@ -346,7 +355,9 @@ class Dictionary
346
355
  end
347
356
 
348
357
  def dup
349
- self.class[*to_a.flatten]
358
+ a = []
359
+ each{ |k,v| a << k; a << v }
360
+ self.class[*a]
350
361
  end
351
362
 
352
363
  def update( hsh2 )
@@ -418,120 +429,3 @@ class Dictionary
418
429
  @hash.dup
419
430
  end
420
431
  end
421
-
422
-
423
-
424
- # _____ _
425
- # |_ _|__ ___| |_
426
- # | |/ _ \/ __| __|
427
- # | | __/\__ \ |_
428
- # |_|\___||___/\__|
429
- #
430
-
431
- =begin testing
432
-
433
- require 'test/unit'
434
-
435
- class TC_Dictionary < Test::Unit::TestCase
436
-
437
- def test_create
438
- hsh = Dictionary['z', 1, 'a', 2, 'c', 3]
439
- assert_equal( ['z','a','c'], hsh.keys )
440
- end
441
-
442
- def test_op_store
443
- hsh = Dictionary.new
444
- hsh['z'] = 1
445
- hsh['a'] = 2
446
- hsh['c'] = 3
447
- assert_equal( ['z','a','c'], hsh.keys )
448
- end
449
-
450
- def test_push
451
- hsh = Dictionary['a', 1, 'c', 2, 'z', 3]
452
- assert( hsh.push('end', 15) )
453
- assert_equal( 15, hsh['end'] )
454
- assert( ! hsh.push('end', 30) )
455
- assert( hsh.unshift('begin', 50) )
456
- assert_equal( 50, hsh['begin'] )
457
- assert( ! hsh.unshift('begin', 60) )
458
- assert_equal( ["begin", "a", "c", "z", "end"], hsh.keys )
459
- assert_equal( ["end", 15], hsh.pop )
460
- assert_equal( ["begin", "a", "c", "z"], hsh.keys )
461
- assert_equal( ["begin", 50], hsh.shift )
462
- end
463
-
464
- def test_insert
465
- # front
466
- h = Dictionary['a', 1, 'b', 2, 'c', 3]
467
- r = Dictionary['d', 4, 'a', 1, 'b', 2, 'c', 3]
468
- assert_equal( 4, h.insert(0,'d',4) )
469
- assert_equal( r, h )
470
- # back
471
- h = Dictionary['a', 1, 'b', 2, 'c', 3]
472
- r = Dictionary['a', 1, 'b', 2, 'c', 3, 'd', 4]
473
- assert_equal( 4, h.insert(-1,'d',4) )
474
- assert_equal( r, h )
475
- end
476
-
477
- def test_update
478
- # with other orderred hash
479
- h1 = Dictionary['a', 1, 'b', 2, 'c', 3]
480
- h2 = Dictionary['d', 4]
481
- r = Dictionary['a', 1, 'b', 2, 'c', 3, 'd', 4]
482
- assert_equal( r, h1.update(h2) )
483
- assert_equal( r, h1 )
484
- # with other hash
485
- h1 = Dictionary['a', 1, 'b', 2, 'c', 3]
486
- h2 = { 'd' => 4 }
487
- r = Dictionary['a', 1, 'b', 2, 'c', 3, 'd', 4]
488
- assert_equal( r, h1.update(h2) )
489
- assert_equal( r, h1 )
490
- end
491
-
492
- def test_merge
493
- # with other orderred hash
494
- h1 = Dictionary['a', 1, 'b', 2, 'c', 3]
495
- h2 = Dictionary['d', 4]
496
- r = Dictionary['a', 1, 'b', 2, 'c', 3, 'd', 4]
497
- assert_equal( r, h1.merge(h2) )
498
- # with other hash
499
- h1 = Dictionary['a', 1, 'b', 2, 'c', 3]
500
- h2 = { 'd' => 4 }
501
- r = Dictionary['a', 1, 'b', 2, 'c', 3, 'd', 4]
502
- assert_equal( r, h1.merge(h2) )
503
- end
504
-
505
- def test_order_by
506
- h1 = Dictionary['a', 3, 'b', 2, 'c', 1]
507
- h1.order_by{ |k,v| v }
508
- assert_equal( [1,2,3], h1.values )
509
- assert_equal( ['c','b','a'], h1.keys )
510
- end
511
-
512
- def test_op_store
513
- h1 = Dictionary[]
514
- h1[:a] = 1
515
- h1[:c] = 3
516
- assert_equal( [1,3], h1.values )
517
- h1[:b,1] = 2
518
- assert_equal( [1,2,3], h1.values )
519
- assert_equal( [:a,:b,:c], h1.keys )
520
- end
521
-
522
- def test_reverse!
523
- hsh = Dictionary['z', 1, 'a', 2, 'c', 3]
524
- hsh.reverse!
525
- assert_equal( ['c','a','z'], hsh.keys )
526
- end
527
-
528
- def test_enumerable
529
- h1 = Dictionary[]
530
- h1[:a] = "a"
531
- h1[:c] = "b"
532
- assert_equal( ["A","B"], h1.collect{|k,v| v.capitalize} )
533
- end
534
-
535
- end
536
-
537
- =end
@@ -195,7 +195,7 @@ class Downloader
195
195
 
196
196
  STDOUT.sync = true
197
197
  begin
198
- local_file = File.open( filepath, 'w' )
198
+ local_file = File.open( filepath, 'wb' )
199
199
  remote_file = open( url, :progress_proc => progress_proc )
200
200
  local_file << remote_file.read
201
201
  rescue
@@ -62,6 +62,7 @@ class InfinityClass < Numeric
62
62
 
63
63
  def initialize(direction=1)
64
64
  @direction = (direction <=> 0)
65
+ super()
65
66
  end
66
67
 
67
68
  # Change direction of infinity.
@@ -172,9 +173,8 @@ class Numeric
172
173
  end
173
174
 
174
175
  # Set constant to positive infinity.
175
-
176
- UNDEFINED = InfinityClass.instance(0)
177
- INFINITY = InfinityClass.instance(1)
176
+ UNDEFINED = InfinityClass.new(0)
177
+ INFINITY = InfinityClass.new(1)
178
178
 
179
179
  NaN = UNDEFINED
180
180
  Inf = INFINITY
@@ -64,7 +64,6 @@ require 'facets/enumerablepass'
64
64
  #
65
65
  # i = Interval[1,3]
66
66
  # i.to_a(1,2) #=> [1.0,1.5,2.0,2.5,3.0]
67
- #
68
67
 
69
68
  class Interval
70
69
 
@@ -265,163 +264,3 @@ class Interval
265
264
  end
266
265
 
267
266
  end
268
-
269
-
270
-
271
- # _____ _
272
- # |_ _|__ ___| |_
273
- # | |/ _ \/ __| __|
274
- # | | __/\__ \ |_
275
- # |_|\___||___/\__|
276
- #
277
-
278
- =begin testing
279
-
280
- require 'test/unit'
281
-
282
- class InclusiveTest < Test::Unit::TestCase
283
-
284
- def setup
285
- @a = Interval.new( 1, 10 )
286
- @b = Interval.new( 1, 10, true, false )
287
- @c = Interval.new( 1, 10, false, true )
288
- @d = Interval.new( 1, 10, true, true )
289
- end
290
-
291
- def test_001A ; assert_equal( false, @a.include?(0) ) ; end
292
- def test_002A ; assert_equal( true, @a.include?(1) ) ; end
293
- def test_003A ; assert_equal( true, @a.include?(2) ) ; end
294
- def test_004A ; assert_equal( true, @a.include?(9) ) ; end
295
- def test_005A ; assert_equal( true, @a.include?(10) ) ; end
296
- def test_006A ; assert_equal( false, @a.include?(11) ) ; end
297
-
298
- def test_001B ; assert_equal( false, @b.include?(0) ) ; end
299
- def test_002B ; assert_equal( false, @b.include?(1) ) ; end
300
- def test_003B ; assert_equal( true, @b.include?(2) ) ; end
301
- def test_004B ; assert_equal( true, @b.include?(9) ) ; end
302
- def test_005B ; assert_equal( true, @b.include?(10) ) ; end
303
- def test_006B ; assert_equal( false, @b.include?(11) ) ; end
304
-
305
- def test_001C ; assert_equal( false, @c.include?(0) ) ; end
306
- def test_002C ; assert_equal( true, @c.include?(1) ) ; end
307
- def test_003C ; assert_equal( true, @c.include?(2) ) ; end
308
- def test_004C ; assert_equal( true, @c.include?(9) ) ; end
309
- def test_005C ; assert_equal( false, @c.include?(10) ) ; end
310
- def test_006C ; assert_equal( false, @c.include?(11) ) ; end
311
-
312
- def test_001D ; assert_equal( false, @d.include?(0) ) ; end
313
- def test_002D ; assert_equal( false, @d.include?(1) ) ; end
314
- def test_003D ; assert_equal( true, @d.include?(2) ) ; end
315
- def test_004D ; assert_equal( true, @d.include?(9) ) ; end
316
- def test_005D ; assert_equal( false, @d.include?(10) ) ; end
317
- def test_006D ; assert_equal( false, @d.include?(11) ) ; end
318
-
319
- end
320
-
321
- class LrgNumericTest < Test::Unit::TestCase
322
-
323
- def setup
324
- @a = Interval.new(0,100000000)
325
- @b = Interval.new(0,100000000)
326
- end
327
-
328
- def test_001A ; assert_equal( true, @a.include?(0) ) ; end
329
- def test_002A ; assert_equal( true, @a.include?(1000) ) ; end
330
- def test_003A ; assert_equal( true, @a.include?(1000000) ) ; end
331
- def test_004A ; assert_equal( true, @a.include?(100000000) ) ; end
332
- #def test_005A ; assert_equal( false, @a.include?(INFINITY) ) ; end
333
-
334
- def test_001B ; assert_equal( true, @b.include?(0) ) ; end
335
- def test_002B ; assert_equal( true, @b.include?(5) ) ; end
336
- def test_002B ; assert_equal( true, @b.include?(70007) ) ; end
337
- def test_002B ; assert_equal( true, @b.include?(5000005) ) ; end
338
- #def test_002B ; assert_equal( false, @b.include?(INFINITY) ) ; end
339
-
340
- end
341
-
342
- class SelectTest < Test::Unit::TestCase
343
-
344
- def setup
345
- @a = Interval.new( 0,10 )
346
- end
347
-
348
- def test_001
349
- b = @a.collect( 2 ){ |n| n }
350
- assert_equal( [0,2,4,6,8,10], b )
351
- end
352
-
353
- def test_002
354
- b = @a.select{ |n| n % 2 == 0 }
355
- assert_equal( [0,2,4,6,8,10], b )
356
- end
357
-
358
- def test_003
359
- b = @a.collect( 1,2 ){ |n| n }
360
- assert_equal( [0,5,10], b )
361
- end
362
-
363
- def test_004
364
- b = @a.select( 1,2 ){ |n| n % 2 == 0 }
365
- assert_equal( [0,10], b )
366
- end
367
-
368
- end
369
-
370
- class ArrayTest < Test::Unit::TestCase
371
-
372
- def setup
373
- @a = Interval.new( 0,10 )
374
- @b = Interval.new( 0,1 )
375
- end
376
-
377
- def test_001A ; assert_equal( [0,5,10], @a.to_a(1,2) ) ; end
378
-
379
- def test_001B ; assert_equal( [0, 0.25, 0.5, 0.75, 1.0], @b.to_a(1,4) ) ; end
380
-
381
- end
382
-
383
- =end
384
-
385
- =begin
386
- class InfTest < Test::Unit::TestCase
387
-
388
- def setup
389
- @a = Interval.new( -INFINITY, -3 )
390
- @b = Interval.new( -INFINITY, -3, true, false )
391
- @c = Interval.new( -3, INFINITY )
392
- @d = Interval.new( -INFINITY, INFINITY )
393
- @e = Interval.new( -3, -2 )
394
- end
395
-
396
- def test_001A ; assert_equal( true, @a.include?(-INFINITY) ) ; end
397
- def test_002A ; assert_equal( true, @a.include?(-4) ) ; end
398
- def test_003A ; assert_equal( true, @a.include?(-3) ) ; end
399
- def test_004A ; assert_equal( false, @a.include?(-2) ) ; end
400
- def test_005A ; assert_equal( false, @a.include?(INFINITY) ) ; end
401
-
402
- def test_001B ; assert_equal( true, @b.include?(-INFINITY) ) ; end
403
- def test_002B ; assert_equal( true, @b.include?(-4) ) ; end
404
- def test_003B ; assert_equal( false, @b.include?(-3) ) ; end
405
- def test_004B ; assert_equal( false, @b.include?(-2) ) ; end
406
- def test_005B ; assert_equal( false, @b.include?(INFINITY) ) ; end
407
-
408
- def test_001C ; assert_equal( false, @c.include?(-INFINITY) ) ; end
409
- def test_002C ; assert_equal( false, @c.include?(-4) ) ; end
410
- def test_003C ; assert_equal( true, @c.include?(-3) ) ; end
411
- def test_004C ; assert_equal( true, @c.include?(-2) ) ; end
412
- def test_005C ; assert_equal( true, @c.include?(INFINITY) ) ; end
413
-
414
- def test_001D ; assert_equal( true, @d.include?(-INFINITY) ) ; end
415
- def test_002D ; assert_equal( true, @d.include?(-4) ) ; end
416
- def test_003D ; assert_equal( true, @d.include?(-3) ) ; end
417
- def test_004D ; assert_equal( true, @d.include?(-2) ) ; end
418
- def test_005D ; assert_equal( true, @d.include?(INFINITY) ) ; end
419
-
420
- def test_001E ; assert_equal( false, @e.include?(-INFINITY) ) ; end
421
- def test_002E ; assert_equal( false, @e.include?(-4) ) ; end
422
- def test_003E ; assert_equal( true, @e.include?(-3) ) ; end
423
- def test_004E ; assert_equal( true, @e.include?(-2) ) ; end
424
- def test_005E ; assert_equal( false, @e.include?(INFINITY) ) ; end
425
-
426
- end
427
- =end
@@ -104,11 +104,13 @@ module Multiton
104
104
  # disable build-in copying methods
105
105
 
106
106
  def clone
107
- self #raise TypeError, "can't clone Multiton #{self}"
107
+ raise TypeError, "can't clone Multiton #{self}"
108
+ #self
108
109
  end
109
110
 
110
111
  def dup
111
- self #raise TypeError, "can't dup Multiton #{self}"
112
+ raise TypeError, "can't dup Multiton #{self}"
113
+ #self
112
114
  end
113
115
 
114
116
  # default marshalling strategy
@@ -157,11 +159,12 @@ module Multiton
157
159
  private
158
160
  def included(base)
159
161
  class << base
162
+ #alias_method(:new!, :new) unless method_defined?(:new!)
160
163
  # gracefully handle multiple inclusions of Multiton
161
- unless include?(Multiton::ClassMethods)
162
- #alias_method :_new, :new
163
- private :allocate, :new #, :new
164
- include Multiton::ClassMethods
164
+ unless include?(Multiton::MetaMethods)
165
+ alias_method :new!, :new
166
+ private :allocate #, :new
167
+ include Multiton::MetaMethods
165
168
 
166
169
  if method_defined?(:marshal_dump)
167
170
  undef_method :marshal_dump
@@ -176,7 +179,7 @@ module Multiton
176
179
 
177
180
  #
178
181
 
179
- module ClassMethods
182
+ module MetaMethods
180
183
 
181
184
  include Inclusive
182
185
 
@@ -185,7 +188,7 @@ module Multiton
185
188
  multiton_instance.fetch(arg) do
186
189
  multiton_mutex[arg].synchronize do
187
190
  multiton_instance.fetch(arg) do
188
- val = multiton_instance[arg] = new(*e, &b) #_new(*e, &b)
191
+ val = multiton_instance[arg] = new!(*e, &b) #new(*e, &b)
189
192
  val.instance_variable_set(:@multiton_initializer, e, &b)
190
193
  multiton_mutex.initialized(arg)
191
194
  val
@@ -193,7 +196,7 @@ module Multiton
193
196
  end
194
197
  end
195
198
  end
196
- #alias_method :new, :instance
199
+ alias_method :new, :instance
197
200
 
198
201
  def initialized?(*e, &b)
199
202
  multiton_instance.key?(multiton_id(*e, &b))
@@ -242,8 +245,8 @@ end
242
245
 
243
246
 
244
247
 
245
-
246
-
248
+ =begin
249
+ # TODO Convert this into a real test and/or benchmark.
247
250
 
248
251
  if $0 == __FILE__
249
252
 
@@ -320,7 +323,7 @@ if $0 == __FILE__
320
323
  super
321
324
  end
322
325
 
323
- def new(*e)
326
+ def new!(*e) # NOTICE!!!
324
327
  super
325
328
  ensure
326
329
  nap()
@@ -351,3 +354,4 @@ if $0 == __FILE__
351
354
  end
352
355
 
353
356
  end
357
+ =end