Hello
Is this correct
class Horse
end
class Horses <Horse
def noh
print 'noh:'
noh = gets.chomp
[noh]
end
end
Main Topics
Browse All TopicsHello
I want to be able to get user input into an array - e.g. run the ruby script and I would like to be prompted to enter user requirements. Below are 2 methods where I have to open the Ruby file and enter my requirements. Ideally I want to run the script and have two prompts so I can enter my data into the arrays
Regards
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Hello - still struggling
If I run the following example from within Scite it works fine and my output is as expected 1 & 2
The code.........
class Phil
end
class Phil2 <Phil
def noh
[1,2,3,4,5]
end
def odds
[10,2,0,0,0]
end
end
a = Phil2.new
lessthanoneh1 = a.noh[0]
lessthanoneh2 = a.noh[1]
puts lessthanoneh1
puts lessthanoneh2
However - I still want to be able to enter data into my array by using gets.chomp and send results to a file.
Below is the code useing gets.chomp - when I run the file the prompt asks for data and I put in
1,2
but instead of getting 1 & 2 - I get 1 & nil
The code using gets.chomp..........
class Phil
end
class Phil2 <Phil
def noh
print "Enter your name: "
noh = gets.chomp.to_i
[noh]
end
end
a = Phil2.new
b = a.noh[0]
c = a.noh[1]
myfile = File.new("c:/horses.txt","
myfile.puts b
myfile.puts c
Andrew
Still not getting 1 & 2
Question when running file from cmd line - I enter 1 from first prompt and 2 from second prompt but in my file it shows 1 & 0
I then added another line e.g.
d = a.noh
then ..
myfile.puts d
Run the file again and as expected 3 prompts - entered 1 then 2 then 3 and output to file was 1,0,1
Hmm?
Could this be a Windows thing?
Business Accounts
Answer for Membership
by: doadesPosted on 2009-08-23 at 14:59:03ID: 25164452
the way to get user input in ruby is to use
"gets.chomp"
for example...
Andrew
Select allOpen in new window