From: Robert Klemme Date: 2012-01-23T21:35:02+09:00 Subject: Re: codepart - please explain! On Sun, Jan 22, 2012 at 7:10 PM, Peter Vandenabeele wrote: > On Sun, Jan 22, 2012 at 6:54 PM, Blub Bla wrote: > >> Hey everyone, >> >> I've found a code part that I don't understand: >> >> >> >> def runCode >>  return <>  (..) >>  STARTCODE >> end >> >> >> Unfortunately the google search doesn't work because the << will be >> ignored. >> Could you explain what it's doing? >> >> Oh, and I can't try out what it's doing because I'll get the error that >> STARTCODE can't be found until EOF... >> > > The technique is called a "here doc". > > First match in Google > >  http://blog.jayfields.com/2006/12/ruby-multiline-strings-here-doc-or.html > > The specific issue in your code example is that you need to use either: > > def runCode >  return <  (..) > STARTCODE  # NO margin left of STARTCODE > end Careful with comments on that line: 13:33:38 Temp$ ruby19 x.rb x.rb:6: can't find string "STARTCODE" anywhere before EOF x.rb:2: syntax error, unexpected $end, expecting tSTRING_CONTENT or tSTRING_DBEG or tSTRING_DVAR or tSTRING_END 13:34:12 Temp$ cat -n x.rb 1 2 s=<