Welcome to Dream.In.Code
Getting Help is Easy!

Join 132,647 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,132 people online right now. Registration is fast and FREE... Join Now!




Ruby Inputs - Wierd?

 
Reply to this topicStart new topic

Ruby Inputs - Wierd?, + Question on 'post 5'

Kingbradley6
post 18 Aug, 2008 - 09:32 AM
Post #1


D.I.C Head

Group Icon
Joined: 10 Jul, 2008
Posts: 116



Thanked 1 times

Dream Kudos: 100
My Contributions


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,

CODE

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...

CODE

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 smile.gif

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 Aug, 2008 - 06:50 AM
User is offlineProfile CardPM

Go to the top of the page

MitkOK
post 19 Aug, 2008 - 12:13 AM
Post #2


D.I.C Regular

Group Icon
Joined: 9 Aug, 2007
Posts: 314



Thanked 12 times

Dream Kudos: 250
My Contributions


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.org/docs/UsersGuide/rg/accessors.html
User is offlineProfile CardPM

Go to the top of the page

Kingbradley6
post 19 Aug, 2008 - 01:21 AM
Post #3


D.I.C Head

Group Icon
Joined: 10 Jul, 2008
Posts: 116



Thanked 1 times

Dream Kudos: 100
My Contributions


QUOTE(MitkOK @ 19 Aug, 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.org/docs/UsersGuide/rg/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 Aug, 2008 - 01:23 AM
User is offlineProfile CardPM

Go to the top of the page

MitkOK
post 19 Aug, 2008 - 02:06 AM
Post #4


D.I.C Regular

Group Icon
Joined: 9 Aug, 2007
Posts: 314



Thanked 12 times

Dream Kudos: 250
My Contributions


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.
User is offlineProfile CardPM

Go to the top of the page

Kingbradley6
post 19 Aug, 2008 - 06:49 AM
Post #5


D.I.C Head

Group Icon
Joined: 10 Jul, 2008
Posts: 116



Thanked 1 times

Dream Kudos: 100
My Contributions


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

By the way, do you know how to turn a ruby file (*.rb) into an executable (*.exe)?
User is offlineProfile CardPM

Go to the top of the page

MitkOK
post 19 Aug, 2008 - 07:37 AM
Post #6


D.I.C Regular

Group Icon
Joined: 9 Aug, 2007
Posts: 314



Thanked 12 times

Dream Kudos: 250
My Contributions


http://www.erikveen.dds.nl/rubyscript2exe/
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 04:54AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month