On Dec 28, 2007 3:20 PM, lrlebron@gmail.com <lrlebron@gmail.com> wrote:
On Dec 28, 12:49 pm, Mark Toth <mark.t...@telia.com> wrote:
> I have this code:
>
> file = "filename.txt"
> File.open(file) do |sFile|
> while line = sFile.gets
> row = line.split("\t")
> a_product = Product.new(
> :sku => row[0] ,
> :name => row[1] ,
> :price => row[2] ,
> a_product.save
> end
> end
>
> What if I want to jump over the first line of the file so it won´t be
> imported?
>
> Thank you,
>
> Mark
> --
> Posted viahttp://www.ruby-forum.com/.
The $. variable holds the line number so you could do something like
this:
File.open("filename.txt") do |aFile|
aFile.each_line do |line|
if $. > 1 #processs data here
How would I know that File.open exists if I didn't look at Kernel?
The way Mark was using it, it made it look like a member of the File
class. Is this just something you have to know, or am I missing
something in ruby doc? I would think http://ruby-doc.org/core/classes/File.html would list all members.
On Dec 28, 2007 4:35 PM, lrlebron@gmail.com <lrlebron@gmail.com> wrote:
On Dec 28, 3:01 pm, Joe <qbpro...@gmail.com> wrote:
> I don't see File.open here:http://ruby-doc.org/core/classes/File.html
> Am I looking in the wrong place?
>
> Also, how do you find out about globals like $. ?
>
> Joe
>
> On Dec 28, 2007 3:20 PM, lrleb...@gmail.com <lrleb...@gmail.com> wrote:
>
>
>
> > On Dec 28, 12:49 pm, Mark Toth <mark.t...@telia.com> wrote:
> > > I have this code:
>
> > > file = "filename.txt"
> > > File.open(file) do |sFile|
> > > while line = sFile.gets
> > > row = line.split("\t")
> > > a_product = Product.new(
> > > :sku => row[0] ,
> > > :name => row[1] ,
> > > :price => row[2] ,
> > > a_product.save
> > > end
> > > end
>
> > > What if I want to jump over the first line of the file so it won´t be
> > > imported?
>
> > > Thank you,
>
> > > Mark
> > > --
> > > Posted viahttp://www.ruby-forum.com/.
>
> > The $. variable holds the line number so you could do something like
> > this:
>
> > File.open("filename.txt") do |aFile|
> > aFile.each_line do |line|
> > if $. > 1
> > #processs data here
>
> > end
> > end
> > end
>
> > Luis
Exactly. It does however list which class is the superclass (IO) and if you
click on that you will see the method IO.open which is the same as File.open.
File.open(__FILE__) do |file| # open this code file
file.gets # read and skip one line
file.each do |line|
puts line # replace this with the needed code
end
end
__END__
James Edward Gray II
···
On Dec 28, 2007, at 1:59 PM, Mark Toth wrote:
Thomas Wieczorek wrote:
On Dec 28, 2007 8:12 PM, Mark Toth <mark.toth@telia.com> wrote:
Stefano Crocco wrote:
Hmmm, it sounds like a great idea! Can you please send me some code for
it?
Exactly. It does however list which class is the superclass (IO) and if you
click on that you will see the method IO.open which is the same as File.open.
HTH,
Sebastian
--
Jabber: sepp2k@jabber.org
ICQ: 205544826