From: Mark Hubbart Date: 2005-09-11T19:11:55+09:00 Subject: Re: RCR to modify #puts and #print inside ERB On 9/10/05, David A. Black wrote: > Hi -- > > On Sun, 11 Sep 2005, Jay Levitt wrote: > > > In article <49958C10-DAD0-4E7C-B9AB-44C6D314A637@refinery.com>, > > gavin@refinery.com says... > >> My personal mental model says that #puts is for outputting content > >> that is the desired output of your program (unlike #warn). An ERB > >> template is a parametrized program in its own right, and its output > >> is the resulting string. If you want debug output, use #warn. > > > > Agreed. I find it interesting that most of the responders to the thread > > aren't active in the Rails group; Rails is where this sort of thing > > *really* would be nice. > > I love Rails and I use it quite a lot. But I like ERB to behave > in the consistent, non-special-cased way it now does, which is > perfectly straightforward given how method calls work in Ruby (which > is a matter of public record :-) I also don't like the idea of > changing things around in the language because the changes would suit > a given application, project, or framework (though in this case, for > me, that's a moot point because I don't think it would be suitable > anyway). I'm getting the idea that the people on each side of this discussion disagree because they have different mental models of what ERB does, and what a ERB document is: 1. ERB just implements very fancy, flexible, string interpolation. or 2. ERB documents are executable code (actual programs), where text prints itself, and code blocks get run. #1 is, I gather, much like the JSP way (though I've never done JSP stuff) #2 is much like PHP. If you are in the #1 camp, I suspect you think this RCR would not be all that much different from one allowing this: "#{puts 23}" #==> "23\n" If you are in camp #2, you probably just wonder why stuff you output via #print or #puts doesn't end up with the rest of your ERB program's output. I'm in camp #2; I came to Ruby from PHP, and think of the template as an actual program, an executable script with controlling statements (Ruby code) embedded in self-printing text. I was shocked and greatly disappointed when I found out that puts didn't work (yes, I thought it was *broken*). I delved deeper and discovered that it was simply due to an implementation issue; I assumed no one had fixed it because it was too complicated a fix. Now, I have a proposal: What if _erbout was made into a StringIO, and we shifted the idea from an ERB template to an ERB program? Then would it make sense for puts to output to _erbout? cheers, Mark (my apologies if any part of this doesn't make sense, it's been a very long day)