[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Reduce three line method to one line

Giant Cranes

2/22/2008 9:49:00 AM

Hi,

I am trying to get the following method down to 1 line so that I can
lazy-load it.

def get_category_data(category_id)
rows = []
FasterCSV.parse(@data) { |row| rows << row if row[0] == category_id }
rows
end

I'm sure that there a few ways to do it in ruby, any pointers would be
much appreciated.

Thanks,
GiantCranes
--
Posted via http://www.ruby-....

3 Answers

Farrel Lifson

2/22/2008 9:56:00 AM

0

On 22/02/2008, Giant Cranes <ruby-forum@gavinjoyce.com> wrote:
> def get_category_data(category_id)
> rows = []
> FasterCSV.parse(@data) { |row| rows << row if row[0] == category_id }
> rows
> end

FasterCSV.parse(@data).select{|row| row[0] == category_id}

Giant Cranes

2/22/2008 10:01:00 AM

0

Farrel Lifson wrote:

> FasterCSV.parse(@data).select{|row| row[0] == category_id}

Fantastic, thanks!

--
Posted via http://www.ruby-....

Thufir Hawat

2/27/2008 9:14:00 AM

0

On Fri, 22 Feb 2008 18:56:09 +0900, Farrel Lifson wrote:


> FasterCSV.parse(@data).select{|row| row[0] == category_id}


This is to import data with the click of a button?


-Thufir