From: Florian Frank Date: 2007-08-19T04:43:49+09:00 Subject: Re: How do you print the first 5 records in an array? Robert Klemme wrote: > Although I'm always fond of solutions using #inject in this case I'm > sorry to say that but this is not only inefficient but totally > obfuscated. If you feel you have to iterate then you can immediately > print members. These are my preferred solutions > > # fast and readable > 5.times {|i| puts @people[i]} > 0.upto(4) {|i| puts @people[i]} > > # might be less efficient but > # very readable > puts @people[0,5] > puts @people[0...5] > puts @people[0..4] Then let's at least use inject to create nice CPS-style solution: puts_first_five = (0...5).inject(lambda {}) { |f, i| lambda { |a| f[a]; puts a[i] } } puts_first_five[@people] -- Florian Frank