From: Simon Strandgaard Date: 2004-03-30T00:19:24+09:00 Subject: proposal - delayed intropolation in heredoc yet another crazy proposal from me.. read on, am I crazy? motivation ========== I use heredocs for small templates, ala class HTML # ... def write_page(body, title, css, filename) html = < #{title} #{body} EOHTML File.open(filename, "w+") {|f| f.write(html) } end # ... end # class HTML Its disturbing to have many such heredocs which breaks indendation completely. The problem with '<<-EOHTML' is that you get the indention from your source into the output. To circumvent this I often make use of <<-EOHTML.gsub(/^\s*/, "") which removes that indentation, however the interpolated text gets also gsub'ed which Im not interested in. I could do eval of <<'EOHTML'.gsub(/^\s*/, ""), but then the simple idea turns into a long beast, which confuses more that it helps. Then it probably better to use doublequotes than heredoc. proposal ======== If we somehow could manipulate the text string before interpolation occured. For instance by executing code on the HereDoc end tag. server> ruby a.rb a.rb:10: can't find string "EOF" anywhere before EOF a.rb:3: syntax error server> expand -t2 a.rb def m inline = "1\n space\n3" text = <<-EOF pre #{inline} post EOF.gsub(/^\s*/, '') text end p m server> Tell me is this a bad idea? -- Simon Strandgaard