From: SonOfLilit Date: 2007-05-30T22:35:23+09:00 Subject: Enumerable#serially - those nifty functions w/o memory footprint Hello, I've seen many people write things like: (1..1000000).to_a. # anything that is a huge enumerable can work as an example collect{|x| num_appearances(x)}.select{|x| x.is_norwegian?}.collect{|x| x.paycheck}.each{|x| p x} I almost wrote something like that myself today. The problem, of course, is the huge memory footprint - collect, select, collect each creates a new temporary array to store the results in. Here's a solution to that problem, exchanging it for a bit of speed (anything that uses those methods could obviously live with that, otherwise another language or method would be used): module Enumerable def serially(&b) self.collect{|x| *([x].instance_eval(&b)} end end Just beware not to use it with sort or any of the "!" methods or with sort or sort_by. Aur