Tutorial help

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]

Anthony Ob wrote:

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

Hi,

On 25.09.2010 22:01, Anthony Ob wrote:

Anthony Ob wrote:

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

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

Markus F. wrote:

Hi,

On 25.09.2010 22:01, Anthony Ob wrote:

Anthony Ob wrote:

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

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

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs