From: Jacob Fugal Date: 2006-04-12T02:30:23+09:00 Subject: Re: Oddities of Iteration On 4/11/06, Nathan Olberding wrote: > puts "
Reports:" > puts "
    " > reports.each do |x| > begin > puts "
  1. " + x.to_s + "
  2. " > rescue > puts "
  3. ...
  4. " > end > end > puts "
" > puts "
" > 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? My guess, your method is defined like this: class Report def to_s puts "yay!" end end As a result, in each iteration, x.to_s prints "yay!" on it's own line. Then x.to_s returns nil (the return value of the puts statement) and "
  • " + nil tries to coerce nil into a String but fails, raising the exception. Try redefining your method as such: class Report def to_s "yay!" end end Jacob Fugal