each_byte question

L

Luis Mcdoguall

Hi,


I am new to Ruby(v 1.8.6),
I will like to know if is possible to
use multiple lines on a block for the each_byte method on strings.


Something like:

coset=9
i=0

message =
"adsfasdfakjhkjhowerjkbvmzbcnvkfhoeiwrukfhzadsfhhfalkhweryiuwyoyqbvbv"

message.each_byte do |letter|
i=+1
if i == coset
puts
else
print letter
end
end
this code will yield : syntax error, unexpected $end, expecting kEND
Any explanation will be appreciated.
Thanks
-L
 
M

markonlinux

Hi Luis,

Hi,

I am new to Ruby(v 1.8.6),
I will like to know if is possible to
use multiple lines on a block for the each_byte method on strings.

Something like:

coset=9
i=0

message =
"adsfasdfakjhkjhowerjkbvmzbcnvkfhoeiwrukfhzadsfhhfalkhweryiuwyoyqbvbv"

message.each_byte do |letter|
  i=+1

i=0
puts i # => 0
i+=1
puts i # => 1
i+=1
puts i # => 2
i=+1
puts i # => 1
i=+5
puts i # => 5

i will always be 1 (ie i = +1)
you want i+=1
  if i == coset
    puts
  else
    print letter
  end
end
this code will yield : syntax error, unexpected $end, expecting kEND
Any explanation will be appreciated.
Thanks
-L


cheers,
 
S

Sebastian Hungerecker

Luis said:
this code will yield : syntax error, unexpected $end, expecting kEND
Any explanation will be appreciated.

If I run your code here, it runs without error (well, i will always be 1, so
the if-part will never execute, but the program finishes successfully without
error message).
 
L

Luis Mcdoguall

Sebastian said:
If I run your code here, it runs without error (well, i will always be
1, so
the if-part will never execute, but the program finishes successfully
without
error message).

hmm!!??
Thanks Sebastian
I will keep investigating then.

-L
 
R

Rob Biedenharn

hmm!!??
Thanks Sebastian
I will keep investigating then.

-L

$end means the end of file
kEND means the 'end' keyword

So the error message is saying: "Hey, I ran out of code when I still
expected to see an 'end' to close a block ('do'), 'if', 'for',
'while', etc."

-Rob

Rob Biedenharn http://agileconsultingllc.com
(e-mail address removed)
 

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,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top