[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

each_byte question

Luis Mcdoguall

2/25/2008 3:33:00 AM

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
--
Posted via http://www.ruby-....

4 Answers

markonlinux

2/25/2008 4:09:00 AM

0

Hi Luis,

On Feb 25, 2:32 pm, Luis Mcdoguall <lmcdoug...@cs.uri.edu> wrote:
> 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
> --
> Posted viahttp://www.ruby-....


cheers,


--
Mark

Sebastian Hungerecker

2/25/2008 6:33:00 AM

0

Luis Mcdoguall wrote:
> 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).


--
Jabber: sepp2k@jabber.org
ICQ: 205544826

Luis Mcdoguall

2/25/2008 2:12:00 PM

0

Sebastian Hungerecker wrote:
> Luis Mcdoguall wrote:
>> 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).

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

-L
--
Posted via http://www.ruby-....

Rob Biedenharn

2/25/2008 3:48:00 PM

0


On Feb 25, 2008, at 9:12 AM, Luis Mcdoguall wrote:
>> Luis Mcdoguall wrote:
>>> this code will yield : syntax error, unexpected $end, expecting kEND
>>> Any explanation will be appreciated.
>>
> 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://agileconsult...
Rob@AgileConsultingLLC.com