# Puts gets

**URL:** <https://www.ruby-forum.com/t/puts-gets/118572>\
**Category:** Ruby\
**Created:** [October 29, 2007, 3:01am UTC](https://www.ruby-forum.com/t/puts-gets/118572 "2007-10-29T03:01:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![llinklater](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/6bbea6/32.png) [@llinklater](https://www.ruby-forum.com/u/llinklater)\
**Post date:** [October 29, 2007, 3:01am UTC](https://www.ruby-forum.com/t/puts-gets/118572/1 "2007-10-29T03:01:51Z")

</div>

I write this:

puts “foo”  
some\_var = gets

I expect the foo to show up before the gets occurs but it does not. Any  
ideas?

---

<div class="post-metadata">

**Author:** ![llinklater](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/6bbea6/32.png) [@llinklater](https://www.ruby-forum.com/u/llinklater)\
**Post date:** [October 29, 2007, 4:06am UTC](https://www.ruby-forum.com/t/puts-gets/118572/2 "2007-10-29T04:06:51Z")

</div>

On 29 Oct 2007, at 11:01, Lloyd L. wrote:

> I write this:
> 
> puts “foo”  
> some\_var = gets
> 
> I expect the foo to show up before the gets occurs but it does  
> not. Any  
> ideas?

The puts maybe buffered. Does this work as you expect:

$stdout.sync = true  
puts “foo”  
some\_var = gets

Alex G.

Bioinformatics Center  
Kyoto University

---

<div class="post-metadata">

**Author:** ![llinklater](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/6bbea6/32.png) [@llinklater](https://www.ruby-forum.com/u/llinklater)\
**Post date:** [October 29, 2007, 11:04am UTC](https://www.ruby-forum.com/t/puts-gets/118572/3 "2007-10-29T11:04:53Z")

</div>

Lloyd L. wrote:

> I write this:
> 
> puts “foo”  
> some\_var = gets
> 
> I expect the foo to show up before the gets occurs but it does not. Any  
> ideas?

Or you could manually flush the buffer:  
puts “foo”  
STDOUT.flush  
some\_var = gets
