From: John W Higgins Date: 2013-02-16T03:09:57+09:00 Subject: Re: [from BASIC to Ruby] so, what's the proper way to replace funcionality of GOTO ? --14dae9cfcb9ac2042004d5c7452a Content-Type: text/plain; charset=ISO-8859-1 On Fri, Feb 15, 2013 at 9:49 AM, Stu P. D'naim wrote: > > And I know there is not GOTO in Ruby, I was asking for advice how should > I re-write code I posted above in a Ruby way ? Looks like no one read > entire original post :( ... (but I don't blame you, it's really long) > > Baseline - you are certainly free to move to classes or any other concepts you want to add on - but this would be a starting point #!/usr/bin/ruby def handle1 puts 'Got 01' end def handle2 puts 'Got 02' end def handleq @cont = 0 end @cont = 1 while @cont == 1 puts 'Pick an option' choice = gets.strip case choice when '1' handle1 when '2' handle2 when 'q' handleq end end John P.S. Probably the trickiest thing in there for you is the gets.strip - ruby will give you back the newline character when the person hits enter #strip removes the last character from the string (newline character). -- > Posted via http://www.ruby-forum.com/. > > --14dae9cfcb9ac2042004d5c7452a Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

On Fri, Feb 15, 2013 at 9:49 AM, Stu P. = D'naim <lists@ruby-forum.com> wrote:

And I know there is not GOTO in Ruby, I was asking for advice how should I re-write code I posted above in a Ruby way ? Looks like no one read
entire original post :( ... (but I don't blame you, it's really lon= g)

<= br>Baseline - you are certainly free to move to classes or any other concep= ts you want to add on - but this would be a starting point

#!/usr/bi= n/ruby

def handle1
=A0 puts 'Got 01'
end

def handle2
= =A0 puts 'Got 02'
end

def handleq
=A0 @cont =3D 0
e= nd

@cont =3D 1

while @cont =3D=3D 1
=A0 puts 'Pick an = option'
=A0 choice =3D gets.strip
=A0 case choice
=A0 when '1'
=A0= =A0=A0 handle1
=A0 when '2'
=A0=A0=A0 handle2
=A0 when = 9;q'
=A0=A0=A0 handleq
=A0 end
end

John

P.S. Pro= bably the trickiest thing in there for you is the gets.strip - ruby will gi= ve you back the newline character when the person hits enter #strip removes= the last character from the string (newline character).


--14dae9cfcb9ac2042004d5c7452a--