Stupid Ruby Problem

Like I said, I’m work­ing on get­ting my Ruby chops up to snuff. I thought it might be fun to do that by port­ing all of the code in Joseph Adler’s fan­tas­tic Base­ball Hacks from Perl to Ruby.

I’m com­ing back to this project after let­ting it go for a while, and sure enough, the prob­lem I was hav­ing when I put it down is still vex­ing me.

One script is intended to grab all of the play-by-play data from retrosheet.org. The files all have urls like this:


http://www.retrosheet.org/1957/1957al.zip

http://www.retrosheet.org/1957/1957nl.zip

http://www.retrosheet.org/1957/1957ml.zip

The snip­pet below is a sim­pli­fied ver­sion of the code I’m using to build the urls. It’s intended to print the urls of each zip file for each league from 1957 to 2006:

year = 1957
leagues = ['al', 'nl', 'ml']leagues.each do |league|
  while year <= 2006
    url = "http://www.retrosheet.org/#{year}/#{year}#{league}.zip"
    puts url
    year += 1
  end
end

How­ever, it doesn’t do that. It only gen­er­ates the urls for the AL files, and I can’t get my brain around why.

I’ll be sure to add the solu­tion when I fig­ure it out, but for now I wanted to just doc­u­ment some of the strug­gles of a Ruby n00b.

Tags: ,

Leave a Reply