# Simple input problem

**URL:** <https://www.ruby-forum.com/t/simple-input-problem/180347>\
**Category:** Ruby\
**Created:** [December 18, 2009, 4:16am UTC](https://www.ruby-forum.com/t/simple-input-problem/180347 "2009-12-18T04:16:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tutiplain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/77aa72/32.png) [@tutiplain](https://www.ruby-forum.com/u/tutiplain)\
**Post date:** [December 18, 2009, 4:16am UTC](https://www.ruby-forum.com/t/simple-input-problem/180347/1 "2009-12-18T04:16:31Z")

</div>

Hello all,

Somehow the following always worked for me before, but tonight, it  
failed, and I don’t understand why:

gets a

It’s a simple gets command! For some reason when I press Enter, the  
cursor just stays there, waiting for more input. What can this be?  
Also, I can’t do gets a, if I haven’t assigned a value to a yet. How is  
that possible? I thought I could use ruby variables without declaring  
them first! Please help, it’s frustrating to get stuck on something so  
basic!

---

<div class="post-metadata">

**Author:** ![tutiplain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/77aa72/32.png) [@tutiplain](https://www.ruby-forum.com/u/tutiplain)\
**Post date:** [December 18, 2009, 4:18am UTC](https://www.ruby-forum.com/t/simple-input-problem/180347/2 "2009-12-18T04:18:01Z")

</div>

Omar C. wrote:

> Hello all,
> 
> Somehow the following always worked for me before, but tonight, it  
> failed, and I don’t understand why:
> 
> gets a
> 
> It’s a simple gets command! For some reason when I press Enter, the  
> cursor just stays there, waiting for more input. What can this be?  
> Also, I can’t do gets a, if I haven’t assigned a value to a yet. How is  
> that possible? I thought I could use ruby variables without declaring  
> them first! Please help, it’s frustrating to get stuck on something so  
> basic!

Never mind! I was doing it wrong, it is

a = gets

!!

---

<div class="post-metadata">

**Author:** ![tutiplain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/77aa72/32.png) [@tutiplain](https://www.ruby-forum.com/u/tutiplain)\
**Post date:** [December 18, 2009, 6:10am UTC](https://www.ruby-forum.com/t/simple-input-problem/180347/3 "2009-12-18T06:10:12Z")

</div>

Hi,

Am Freitag, 18. Dez 2009, 12:18:03 +0900 schrieb Omar C.:

> Omar C. wrote:
> 
> > gets a
> 
> Never mind! I was doing it wrong, it is
> 
> a = gets

Be aware that `gets' will return`nil’ when the user presses  
Ctrl-D. Saying

gets.chomp

will raise an exception then.

Bertram

---

<div class="post-metadata">

**Author:** ![tutiplain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/77aa72/32.png) [@tutiplain](https://www.ruby-forum.com/u/tutiplain)\
**Post date:** [December 18, 2009, 1:55pm UTC](https://www.ruby-forum.com/t/simple-input-problem/180347/4 "2009-12-18T13:55:00Z")

</div>

Thanks, I will keep that in mind.
