Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Ruby Basics Ruby Syntax Method Return Values

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,252 Points

Git Bash waits for user input before running the program

I'm using Git Bash on Windows rather than Workspaces to follow along. Here's the code I'm testing.

def ask(question)
    print question

    # get input from user
    gets    
end


puts "Welcome to the Widget Store!"

answer = ask("How many widgets are you ordering?")
puts answer

What I'm expecting is that I should see the welcome message and then be presented with the question.

But I have to type in the answer before I receive any output from the console at all.

e.g.

$ ruby widgets.rb
5
Welcome to the Widget Store!
How many widgets are you ordering?5

Any idea how I might fix this in my console? Thanks :)

1 Answer

Manish Giri
Manish Giri
16,266 Points

It's working fine on my end (Linux terminal) -

 % ruby test.rb
Welcome to the Widget Store!
How many widgets are you ordering?5   
5
Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,252 Points

It's just occurred to me I need to use my Ruby command line interpreter, which works as expected, to run ruby programs. Thanks for the inspiration :)