From: "Shannon Fang" <xrfang / hotmail.com> [snipped]


> text.gsub!(/&#(\d+);/) do
>    begin
>       $1.to_i.chr
>    rescue
>    end;
> end
>
> Can anyone explain to me the general rules of when I can write code on
> one line, and when I must write it on multiple lines?

I would trust that (\d+) will succesfully turn into an integer and forget
exception handling:

   text.gsub!(!(/&#(\d+);/) { $1.to_i }

I don't know what you could possibly have to rescue, anyway, because $1 will
always be a string in that context, so #to_i will succeed.

As a matter of style, I never use do ... end on a single line.  I use do ...
end for "procedures" (i.e. *do* something) and { ... } for evaluation purposes.

Sorry to not answer your question fully, but hopefully this will help a bit.

Gavin