From: Logan Capaldo Date: 2007-01-31T07:35:43+09:00 Subject: Re: Ruby << is ambiguos On Mon, Jan 29, 2007 at 09:55:15AM +0900, dblack@wobblini.net wrote: > This message is in MIME format. The first part should be readable text, > while the remaining parts are likely unreadable without MIME-aware tools. > Hi -- > > On Mon, 29 Jan 2007, Wolfgang N�dasi-Donner wrote: > > >Yukihiro Matsumoto schrieb: > >>|irb(main):007:0> angy < >>|irb(main):008:0" xxxxx > >>|irb(main):009:0" EOT > >>|NameError: uninitialized constant EOT > >>| from (irb):7 > >> > >>Ruby knows angy is a local variable, so that the interpreter consider > >>it is more likely a shift operator than a here-doc. If you want to > >>disambiguate, use parentheses. > > > >I made an error there. "angy" followed by a String doesn't make any sense. > >It works very well if written in in a senseful way. > > > >irb(main):001:0> angy = "abc" > >=> "abc" > >irb(main):002:0> angy <<< >irb(main):003:0" ddd > >irb(main):004:0" EOT > >=> "abcddd\n" > > > >But... - there is one thing I really don't understand in the first > >example. Ruby recognizes "EOT" as an uninitialized constant, because "<<" > >ist interpreted as shift operator. But why is an open here-doc string > >recognized in line 008:0" in the example? > > I'm not quite sure either, but it seems to interpret < start of a heredoc, and then later realize that it couldn't have been. > Compare what happens if there's a space before EOT: > > irb(main):012:0> a = 1 > => 1 > irb(main):013:0> a << EOT > NameError: uninitialized constant EOT > from (irb):13 > I suspect part of the problem is that irb lexes your input to determine the continuation prompt (and indeed if it should allow multiple lines of input before evalling). IOW, irb has the same problem our poor text editor's do :) > > David > > -- > Q. What is THE Ruby book for Rails developers? > A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black) > (See what readers are saying! http://www.rubypal.com/r4rrevs.pdf) > Q. Where can I get Ruby/Rails on-site training, consulting, coaching? > A. Ruby Power and Light, LLC (http://www.rubypal.com)