From: "Иван Бишевац" Date: 2012-11-29T18:07:20+09:00 Subject: Re: sorting data from a file --e89a8ffbaecd2d580b04cf9e9c49 Content-Type: text/plain; charset=UTF-8 It's beginner question. My advice is that you go through some beginners tutorial about Ruby. After that you will know to implement it. Here is your starting code: require 'csv' class ParseCSV def initialize @csv = CSV.read "data.csv" end def test @csv[0] # it's first row end end pc = ParseCSV.new pc.test As you see it's easier to process your data by csv class, since it's in comma separaterd values format. In constructor you initialize @csv variable which is 2 dimensional array. You acces it through indexes. For example to get 1st cell, then you type @csv[0][0]. You get first row by @csv[0]. If you want to go through all rows then you type: @csv.each do |row| 2012/11/28 Jan E. > You can argue all day long about which solution is easier to understand > and better for a beginner. But personally, I'm more interested in which > methods *he* knows. If he knows File.readlines, that's fine. Then we can > use it. If he knows File.foreach, that's fine, too. > > I know Ruby programmers love endless discussions about the best > solution. But it would be great if maybe this time you could not do that > and just help. > > > @ Ismail: > > Please write down everything that you currently have (ideas, code, > whatever). Your code snippet for the smallest number is already useful. > You'll be able to use that later. > > -- > Posted via http://www.ruby-forum.com/. > > --e89a8ffbaecd2d580b04cf9e9c49 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable It's beginner question. My advice is that you go through some beginners= tutorial about Ruby. After that you will know to implement it. Here is you= r starting code:
require 'csv'

class ParseCSV
def initiali= ze
@csv =3D C= SV.read "data.csv"
end
def test
@csv[0] # it's first row
end
end

=
pc =3D ParseCSV.new
pc.test

=
As you see it's easier to process your data by csv class, since it'= s in comma separaterd values format. In constructor you initialize @csv var= iable which is 2 dimensional array. You acces it through indexes. For examp= le to get 1st cell, then you type @csv[0][0]. You get first row by @csv[0].=

If you want to go through all rows then you type:
=
@csv.each do |row|

--e89a8ffbaecd2d580b04cf9e9c49--