On Saturday 02 October 2004 11:55 pm, James Edward Gray II wrote: > Ruby's here-doc syntax baffles me. I don't get the indent the end tag > feature. > > string = <<-END_OF_STRING > Line one... > line two... > line three. > END_OF_STRING > > That leaves all the tabs at the beginning of those lines, which then > begs the question, why did I bother to indent the end tag? > > It would make a lot more sense to me if lines of a here-doc were > stripped of leading whitespace equal to the indention of the end tag. > Is there any reason this wasn't done, or isn't practical? > > If not, please consider this an official request, by at least one > coder... I concur. That would be nice. Likewise I have asked about a margin controlled literal (%l, %L). In the mean time I've used this on occasion: class String # provides a margin controlled string # # x = %Q{ # | This # | is # | margin controlled! # }.margin # def margin(d='|') gsub(/^\s*[#{d}]/, '') end end Could work for here-docs too I suppose. irb(main):001:0> require 'succ/string/tabs' => true irb(main):002:0> t = <<-HERE.margin irb(main):003:0" | test irb(main):004:0" | this irb(main):005:0" | out irb(main):006:0" HERE => " test\n this\n out\n" Yep. T.