On Oct 12, 12:41 am, "yer... / gmail.com" <yer... / gmail.com> wrote:
> On Oct 12, 12:13 am, Michael Linfield <globyy3... / hotmail.com> wrote:
>
> > Shuaib Zahda wrote:
> > > Hello
>
> > > I am doing a program in which I want to allow my user to keep keying in
> > > until they put semicolon then the prompt will process the data. It is
> > > something like mysql way. for example
>
> > > mysql> select
> > >> * from
> > >> user;
>
> > > I want to have something like this.
>
> > while gets.chomp != ";"
> >   #code here
>
> I don't think this does what you think it does. String#chomp takes a
> character as its argument, with '\n' being the default. The final
> character of the String is removed iff that character is the same as
> the argument character. String#chomp then returns whatever remains of
> the calling String, not the removed character.
>
> Instead, try
>
> all_input = ""
> while line = gets
>   line.chomp!
>   next if line.nil?
>   all_input << line
>   break if line[-1].chr == ';'
> end
> puts "got: #{all_input}"
>

which isn't completely correct either, but the general idea is there
and it's my bedtime.

> > > the other question, how can I read the last char as char in a string
> > > because it keeps returning the ASCII value
>
> > Sorry but i dont quite understand your 2nd question :(  Maybe elaborate
> > a little?
>
> I think the second question refers to the fact that
> "hello"[0] => 104
>
> when
> "hello"[0].chr => "h"
> is the desired behavior.