Tutorial help

A

Anthony Ob

http://rubylearning.com/satishtalim/variables_and_assignment.html

the a =<<END_STR
spits out an error
Here is what I coded with the tutorial
[code/]#p004stringusage.rb
#defining a constant
PI = 3.1416
puts PI
# Defining a local variable
myString = 'I love my city, Pune'
puts myString
=begin
conversions
to_i, .to_f, .to_s
=end
var1=5;
var2='2'
puts var1+var2.to_i
#<< appending to a string
a='hello'
a<<'world.
I love this world...'
puts a
=begin << marks the start of the string literal and is followed by a
dlimiter of your choice. The string literal then starts from the next
new line and finishes when the delimiter is repeated again on a line
of it own. This is know as Here document syntax.
=end
a = <<END_STR
#This is the string and a second line
ENG_STR
puts a[/code]
 
A

Anthony Ob

Anthony said:
http://rubylearning.com/satishtalim/variables_and_assignment.html

the a =<<END_STR
spits out an error
Here is what I coded with the tutorial
[code/]#p004stringusage.rb
#defining a constant
PI = 3.1416
puts PI
# Defining a local variable
myString = 'I love my city, Pune'
puts myString
=begin
conversions
.to_i, .to_f, .to_s
=end
var1=5;
var2='2'
puts var1+var2.to_i
#<< appending to a string
a='hello'
a<<'world.
I love this world...'
puts a
=begin << marks the start of the string literal and is followed by a
dlimiter of your choice. The string literal then starts from the next
new line and finishes when the delimiter is repeated again on a line
of it own. This is know as Here document syntax.
=end
a = <<END_STR
#This is the string and a second line
ENG_STR
puts a[/code]

btw here is the error message
p004stringusage.rb:28: can't find string "END_STR" anywhere before EOF
p004stringusage.rb:25: syntax error, unexpected $end, expecting
tSTRING_CONTENT
or tSTRING_DBEG or tSTRING_DVAR or tSTRING_END
 
M

Markus Fischer

Hi,

btw here is the error message
p004stringusage.rb:28: can't find string "END_STR" anywhere before EOF
p004stringusage.rb:25: syntax error, unexpected $end, expecting
tSTRING_CONTENT
or tSTRING_DBEG or tSTRING_DVAR or tSTRING_END

Oh .. it's a tricky one. I tried it myself and the problem is caused due
the trailing whitespace on the lines containing END_STR. They come from
copying the example from the web page.

Simply remove them and the example should work.

HTH
 
A

Anthony Ob

Markus said:
Hi,



Oh .. it's a tricky one. I tried it myself and the problem is caused due
the trailing whitespace on the lines containing END_STR. They come from
copying the example from the web page.

Simply remove them and the example should work.

HTH

Lmao im such a noob; Instead of a D in END_STR I put G. smh Thanks for
the help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top