Ruby Inputs - Wierd?

+ Question on 'post 5'

Page 1 of 1

5 Replies - 3130 Views - Last Post: 19 August 2008 - 08:37 AM Rate Topic: -----

#1 Kingbradley6  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 150
  • Joined: 10-July 08

Ruby Inputs - Wierd?

Posted 18 August 2008 - 10:32 AM

I'm a bit confused with the input's of Ruby.

Whenever I try to get input, it doesn't register the 'Backspace' key. Also, it never accepts the 'Enter' first time. I always have to push 'Enter' after my input usually 3 times before it actually inputs it.

For example,

my_var = gets.chomp



If I wanted to enter 'Hello', I would have to type it followed by pressing the return key 3 times before it actually entered it.

Now I did find a way to solve this using...

STDOUT.flush
my_var = gets.chomp



But...

1) This seems wierd having to enter that EVERY time before I want input?

2) It still doesn't solve the problem of registering backspace.

If I was to type directly 'Hello World' but with two accidental keystrokes such as this: Hello Worpold

Even if I used the backspace so it appeared as I was entering: Hello World

If I then went on to 'puts' or 'print' that it would output: Hello Worpold

Know how I can fix it so it accepts backspace and know any other ways of missing out STDOUT.flush?

Thanks in advance

P.S. Apart from this Ruby seems nice and I've already, within my first day of learning, created a whole program that grows a tree and you can pick oranges :)

P.P.S.

Is there a way of specifiying a variable that can be read/equality tested both in a class and not in a class - in the program seperate?

This post has been edited by Kingbradley6: 19 August 2008 - 07:50 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Ruby Inputs - Wierd?

#2 MitkOK  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 32
  • View blog
  • Posts: 403
  • Joined: 09-August 07

Re: Ruby Inputs - Wierd?

Posted 19 August 2008 - 01:13 AM

This is really strange. In Ubuntu and Mac OS X Leopard everything is fine, no need of flush and no problems with backspace. Ruby version 1.8.6.

I don't think I understand your question in P.P.S, maybe you refer to attribute accessors ?
http://www.ruby-doc..../accessors.html
Was This Post Helpful? 0
  • +
  • -

#3 Kingbradley6  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 150
  • Joined: 10-July 08

Re: Ruby Inputs - Wierd?

Posted 19 August 2008 - 02:21 AM

View PostMitkOK, on 19 Aug, 2008 - 01:13 AM, said:

This is really strange. In Ubuntu and Mac OS X Leopard everything is fine, no need of flush and no problems with backspace. Ruby version 1.8.6.

I don't think I understand your question in P.P.S, maybe you refer to attribute accessors ?
http://www.ruby-doc..../accessors.html


Oh lol, ignore my P.P.S. I was being dumb - the answer I was looking for is global variables lol. Just wasn't thinking at that point. I am new to ruby afterall.

I'm using Ruby182-15, on a Windows Vista and using SciTE IDE. Even with flush it doesn't accept the backspace. Although you see the backspace take affect, it actually doesn't on the variable so when you call the variable it will output the whole input even with the spelling mistakes.

This post has been edited by Kingbradley6: 19 August 2008 - 02:23 AM

Was This Post Helpful? 0
  • +
  • -

#4 MitkOK  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 32
  • View blog
  • Posts: 403
  • Joined: 09-August 07

Re: Ruby Inputs - Wierd?

Posted 19 August 2008 - 03:06 AM

Have you tried running your app in the console instead of SciTE, or in irb ?
The latest version of Ruby is 1.8.6, so maybe be you can take a shot.
Was This Post Helpful? 0
  • +
  • -

#5 Kingbradley6  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 150
  • Joined: 10-July 08

Re: Ruby Inputs - Wierd?

Posted 19 August 2008 - 07:49 AM

Ok I tried running it from the console - it works :) guess it must be just SciTE.

By the way, do you know how to turn a ruby file (*.rb) into an executable (*.exe)?
Was This Post Helpful? 0
  • +
  • -

#6 MitkOK  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 32
  • View blog
  • Posts: 403
  • Joined: 09-August 07

Re: Ruby Inputs - Wierd?

Posted 19 August 2008 - 08:37 AM

http://www.erikveen....rubyscript2exe/
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1