LazyEnumerable 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,11 +6,11 @@ module Lazy
6
6
  ## Remove any unnecessary methods so that method_missing is invoked
7
7
  ##
8
8
  def self.wack_all_my_methods
9
- to_wack=instance_methods.reject do |each|
9
+ to_wack = instance_methods.reject do |each|
10
10
  ['===','method_missing'].include?(each) || each =~ /^__/
11
11
  end
12
12
  to_wack.each do |each|
13
- alias_method(("_" << each), each)
13
+ alias_method("_#{each}", each)
14
14
  undef_method(each)
15
15
  end
16
16
  end
@@ -21,7 +21,7 @@ module Lazy
21
21
 
22
22
  def self.iterator_creator_for(method_name)
23
23
  non_lazy_name = /lazy_(.+)/.match(method_name.to_s)[1].to_sym
24
- define_method(method_name) { Iterator.new(_method(non_lazy_name)) }
24
+ define_method(method_name) { iterator_class.new(_method(non_lazy_name)) }
25
25
  end
26
26
 
27
27
  wack_all_my_methods
@@ -38,5 +38,13 @@ module Lazy
38
38
  def to_lazy
39
39
  self
40
40
  end
41
+
42
+ ##
43
+ ## This should be added with definition of the iterator class
44
+ ##
45
+ def iterator_class
46
+ raise(NotImplementedError, "iterator_class", caller);
47
+ end
48
+
41
49
  end
42
50
  end
@@ -71,7 +71,7 @@ module Lazy
71
71
  end
72
72
 
73
73
  def to_real
74
- _collect(PLACEBO)
74
+ _collect(&PLACEBO)
75
75
  end
76
76
 
77
77
  end
@@ -10,7 +10,7 @@
10
10
  ###
11
11
  module Lazy
12
12
 
13
- class Iterator < AbstractEnumerable
13
+ class MessageCollector < AbstractEnumerable
14
14
 
15
15
  def initialize(proc)
16
16
  @internal=proc
@@ -39,7 +39,7 @@ module Lazy
39
39
  ## Do a placebo collect to get it to create an array with the elements
40
40
  ##
41
41
  def to_real
42
- collect { |each| each }
42
+ collect(&PLACEBO)
43
43
  end
44
44
 
45
45
  ##
@@ -49,9 +49,8 @@ module Lazy
49
49
  ## to change this in the future.
50
50
  ##
51
51
  def each(&block)
52
- method_missing(:each, &block) if (block.nil?)
53
- answer=@internal.call do |each|
54
- result=@sends.inject(each) do |result, each_send |
52
+ answer = @internal.call do |each|
53
+ @sends.inject(each) do |result, each_send |
55
54
  each_send.call(result)
56
55
  end
57
56
  end
@@ -60,4 +59,10 @@ module Lazy
60
59
 
61
60
  end
62
61
 
62
+ class AbstractEnumerable
63
+ def iterator_class
64
+ MessageCollector
65
+ end
66
+ end
67
+
63
68
  end
@@ -4,4 +4,4 @@ require 'lazy/lazy_enumerable'
4
4
  require 'lazy/collect_enumerable'
5
5
  require 'lazy/reject_enumerable'
6
6
  require 'lazy/select_enumerable'
7
- require 'lazy/iterator'
7
+ require 'lazy/message_collector'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: LazyEnumerable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blaine Buxton
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-06-21 00:00:00 -05:00
12
+ date: 2008-10-05 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -29,8 +29,8 @@ files:
29
29
  - lib/lazy/abstract_enumerable.rb
30
30
  - lib/lazy/collect_enumerable.rb
31
31
  - lib/lazy/extensions.rb
32
- - lib/lazy/iterator.rb
33
32
  - lib/lazy/lazy_enumerable.rb
33
+ - lib/lazy/message_collector.rb
34
34
  - lib/lazy/reject_enumerable.rb
35
35
  - lib/lazy/select_enumerable.rb
36
36
  - lib/lazy_enumerable.rb