Call a block method on an iterator: each.magic.collect { ... }
- by blinry
I have a class with a custom each-method:
class CurseArray < Array
def each_safe
each.do |element|
unless element =~ "fuck"
yield element
end
end
end
end
And want to call block methods on those "selected" elements. For example:
curse_array.each_safe.magic.collect {|element| "#{element} is a nice sentence."}
I know there is a way to do this, but I've forgotten. Please help! :-)