From: Nathan Olberding Date: 2006-04-12T01:06:46+09:00 Subject: Oddities of Iteration I'm working on a CGI script that iterates through a list of items of a class I've defined (class Report). Report::to_s just returns the string "yay!" for testing purposes. When I run this code: --------------------- puts "
Reports:" puts "
    " reports.each do |x| begin puts "
  1. " + x.to_s + "
  2. " rescue puts "
  3. ...
  4. " end end puts "
" puts "
" ------------------------------ This is the output (raw HTML): ------------------------------
Incoming Reports:
    yay!
  1. ...
  2. yay!
  3. ...
  4. yay!
  5. ...
  6. yay!
  7. ...
  8. yay!
  9. ...
  10. yay!
  11. ...
  12. yay!
  13. ...
  14. yay!
  15. ...
  16. yay!
  17. ...
  18. yay!
  19. ...
-------------------- As you can see, the "yay!" is supposed to appear surrounded by li tags, but it never does. I have absolutely no idea why I'd need the exception handling code given my data set, but between each iteration, an exception is raised (can't convert nil in to String). It *is* saying "yay!" for each report in the data set, and I can verify this by making Report::to_s say something more identifying. So I'm trying to unravel two mysteries: 1) Why aren't the "yay!"s surrounded by li tags? 2) Why are exceptions being raised between each iteration, yet each item in the data set being iterated through passes through without exception? I realize this probably isn't enough code to discern all the peculiarities, but I'm just not sure what other parts would be useful. Sorry in advance! -- Posted via http://www.ruby-forum.com/.