Lets say, we have an Array of Strings named words and I want to instantiate a special Enumerator using eunum_for on it which only counts Strings with the length != 3. Here is my proposal:
def words.n_each
select{|x| x.length != 3}.each do |y|
yield y
end
end
e4 = words.enum_for(:n_each)
e4.each do |w|
puts w
end
But there has to be a more smarter rubyish way to include the mechanics of the n_each method in enum_for - maybe inside a codeblock at the time of instantiation of the Enumerator. But how?
e4 = words.enum_for(:select, {|x| x.length != 3}or something similar.