Go Back   Rhinocerus > Newsgroup > Newsgroup comp.lang.ruby

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 02-18-2011, 08:25 PM
Nericl Lau
Guest
 
Posts: n/a
Default question for newbie

a = << END_STR
This is the string
And a second line
END_STR
puts a


What does it mean?
I kept getting this error


q1.rb:1: syntax error, unexpected tLSHFT
a = << END_STR

--
Posted via http://www.ruby-forum.com/.

Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

  #2 (permalink)  
Old 02-18-2011, 08:43 PM
Rob Biedenharn
Guest
 
Posts: n/a
Default Re: question for newbie

On Feb 18, 2011, at 4:25 PM, Nericl Lau wrote:

> a = << END_STR
> This is the string
> And a second line
> END_STR
> puts a
>
>
> What does it mean?
> I kept getting this error
>
>
> q1.rb:1: syntax error, unexpected tLSHFT
> a = << END_STR
>


It means that you can't have a space or it looks like you're trying to
use the "left shift" operator <<

a = <<END_STR
This is the string
And a second line
END_STR
puts a

Or using the option to allow the ending tag to be indented:

a = <<-END_STR
This is the string
And a second line
END_STR
puts a

Should do what you want.

-Rob

Rob Biedenharn
Rob@AgileConsultingLLC.com http://AgileConsultingLLC.com/
rab@GaslightSoftware.com http://GaslightSoftware.com/


Reply With Quote
  #3 (permalink)  
Old 02-18-2011, 08:43 PM
Stu
Guest
 
Posts: n/a
Default Re: question for newbie

[Note: parts of this message were removed to make it a legal post.]

you need to remove the space between << and END_STR for the heredoc to work

like so

here = <<EOF
I am inside
a here doc
EOF

puts here

On Fri, Feb 18, 2011 at 3:25 PM, Nericl Lau <nericlau@gmail.com> wrote:

> a = << END_STR
> This is the string
> And a second line
> END_STR
> puts a
>
>
> What does it mean?
> I kept getting this error
>
>
> q1.rb:1: syntax error, unexpected tLSHFT
> a = << END_STR
>
> --
> Posted via http://www.ruby-forum.com/.
>
>


Reply With Quote
  #4 (permalink)  
Old 02-18-2011, 08:45 PM
Jason Stewart
Guest
 
Posts: n/a
Default Re: question for newbie

On Fri, Feb 18, 2011 at 4:25 PM, Nericl Lau <nericlau@gmail.com> wrote:
> a = << END_STR
> This is the string
> And a second line
> END_STR
> puts a
>
>
> What does it mean?
> I kept getting this error
>
>
> q1.rb:1: syntax error, unexpected tLSHFT
> a = << END_STR
>


That's called a heredoc string. See
http://www.ruby-doc.org/docs/ruby-do....html#here_doc
you have an extra space between << and END_STR

try this:
a = <<END_STR
hello world
END_STR
puts a

Reply With Quote
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT. The time now is 09:09 AM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.