From: Gavin Sinclair Date: 2002-09-02T07:25:30+09:00 Subject: Re: Ruby aesthetic ----- Original Message ----- From: "Dossy" > I can't tell who originally wrote this, but: > > >>I'll conclude with one (new) feature from Python that makes me green with > > >>envy: list comprehensions. For those who don't know what that means, > > >>here's an example: > > >> > > >>Ruby: squares_less_than_10 = numbers.find_all{|i| i<10}.map{|i| i^2} > > >> > > >>Python: squares_less_than_10 = [x^2 for x in numbers if x < 10] > > What about this in Ruby, instead: > > squares_less_than_10 = numbers.collect { |x| x**2 if x < 10 } - [nil] > > -- Dossy > That's nice. Do you know you can use #compact as well? Gavin