Class: I18n::Inflector::LazyEnumerator
- Inherits:
-
Enumerator
- Object
- Enumerator
- I18n::Inflector::LazyEnumerator
- Defined in:
- lib/i18n-inflector/lazy_enum.rb,
lib/i18n-inflector/lazy_enum.rb,
lib/i18n-inflector/lazy_enum.rb more...
Overview
This class adds some lazy operations for collections
Direct Known Subclasses
Defined Under Namespace
Classes: Yielder
Class Method Summary collapse
-
.for(enumerable) ⇒ I18n::Inflector::LazyEnumerator
Create a new instance that iterates over the passed Enumerable.
Instance Method Summary collapse
-
#+(other) ⇒ I18n::Inflector::LazyEnumerator
Addition operator for collections.
-
#append(value) ⇒ I18n::Inflector::LazyEnumerator
Appending operator for collections.
-
#empty? ⇒ Boolean
Checks if a collection is empty.
-
#initialize(*args, &block) ⇒ LazyEnumerator
constructor
A new instance of LazyEnumerator.
-
#insert(value) ⇒ I18n::Inflector::LazyEnumerator
Insertion operator for collections.
-
#map(&block) ⇒ I18n::Inflector::LazyEnumerator
Mapping enumerator.
-
#reject(&block) ⇒ I18n::Inflector::LazyEnumerator
Rejecting enumerator.
-
#select(&block) ⇒ I18n::Inflector::LazyEnumerator
Selecting enumerator.
Constructor Details
permalink #initialize(*args, &block) ⇒ LazyEnumerator
Returns a new instance of LazyEnumerator.
45 46 47 |
# File 'lib/i18n-inflector/lazy_enum.rb', line 45 def initialize(*args, &block) args.empty? ? super(Yielder.new(&block)) : super(*args, &nil) end |
Class Method Details
permalink .for(enumerable) ⇒ I18n::Inflector::LazyEnumerator
Create a new instance that iterates over the passed Enumerable
68 69 70 71 72 73 74 |
# File 'lib/i18n-inflector/lazy_enum.rb', line 68 def self.for(enumerable) new do |y| enumerable.each do |e| y << e end end end |
Instance Method Details
permalink #+(other) ⇒ I18n::Inflector::LazyEnumerator
Addition operator for collections
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/i18n-inflector/lazy_enum.rb', line 78 def +(other) self.class.new do |yielder| each do |v| yielder << v end other.each do |v| yielder << v end end end |
permalink #append(value) ⇒ I18n::Inflector::LazyEnumerator
Appending operator for collections
102 103 104 105 106 107 108 109 |
# File 'lib/i18n-inflector/lazy_enum.rb', line 102 def append(value) self.class.new do |yielder| each do |v| yielder << v end yielder << value end end |
permalink #empty? ⇒ Boolean
Checks if a collection is empty
143 144 145 146 147 148 149 150 |
# File 'lib/i18n-inflector/lazy_enum.rb', line 143 def empty? self.class.new do |yielder| each do |k,v| return false end end true end |
permalink #insert(value) ⇒ I18n::Inflector::LazyEnumerator
Insertion operator for collections
91 92 93 94 95 96 97 98 |
# File 'lib/i18n-inflector/lazy_enum.rb', line 91 def insert(value) self.class.new do |yielder| yielder << value each do |v| yielder << v end end end |
permalink #map(&block) ⇒ I18n::Inflector::LazyEnumerator
Mapping enumerator
113 114 115 116 117 118 119 |
# File 'lib/i18n-inflector/lazy_enum.rb', line 113 def map(&block) self.class.new do |yielder| each do |v| yielder << block[v] end end end |
permalink #reject(&block) ⇒ I18n::Inflector::LazyEnumerator
Rejecting enumerator
133 134 135 136 137 138 139 |
# File 'lib/i18n-inflector/lazy_enum.rb', line 133 def reject(&block) self.class.new do |yielder| each do |v| yielder << v unless block[v] end end end |
permalink #select(&block) ⇒ I18n::Inflector::LazyEnumerator
Selecting enumerator
123 124 125 126 127 128 129 |
# File 'lib/i18n-inflector/lazy_enum.rb', line 123 def select(&block) self.class.new do |yielder| each do |v| yielder << v if block[v] end end end |