PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > each_byte question
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
each_byte question

Réponse
 
LinkBack Outils de la discussion
Vieux 25/02/2008, 03h32   #1
Luis Mcdoguall
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut each_byte question

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 =
"adsfasdfakjhkjhowerjkbvmzbcnvkfhoeiwrukfhzadsfhhf alkhweryiuwyoyqbvbv"

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-forum.com/.

  Réponse avec citation
Vieux 25/02/2008, 04h09   #2
markonlinux@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: each_byte question

Hi Luis,

On Feb 25, 2:32pm, 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 =
> "adsfasdfakjhkjhowerjkbvmzbcnvkfhoeiwrukfhzadsfhhf alkhweryiuwyoyqbvbv"
>
> 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-forum.com/.



cheers,


--
Mark
  Réponse avec citation
Vieux 25/02/2008, 06h33   #3
Sebastian Hungerecker
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: each_byte question

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

  Réponse avec citation
Vieux 25/02/2008, 14h12   #4
Luis Mcdoguall
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: each_byte question

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-forum.com/.

  Réponse avec citation
Vieux 25/02/2008, 15h48   #5
Rob Biedenharn
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: each_byte question


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://agileconsultingllc.com
Rob@AgileConsultingLLC.com



  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 12h56.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12867 seconds with 13 queries