# Newbe - strange behavior of print

**URL:** <https://www.ruby-forum.com/t/newbe-strange-behavior-of-print/91661>\
**Category:** Ruby\
**Created:** [April 11, 2007, 9:21am UTC](https://www.ruby-forum.com/t/newbe-strange-behavior-of-print/91661 "2007-04-11T09:21:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![caof2005](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/97f17d/32.png) [@caof2005](https://www.ruby-forum.com/u/caof2005)\
**Post date:** [April 11, 2007, 9:21am UTC](https://www.ruby-forum.com/t/newbe-strange-behavior-of-print/91661/1 "2007-04-11T09:21:05Z")

</div>

Hello folks, this is the scenario:  
I tried to run the following code in EasyEclipse for Ruby IDE and  
SciTE on WinXP  
Both has the same behavior.

def main  
print "Enter the number of employees: "  
numEmp = gets  
puts "The number of employees is:= " + numEmp.to\_s  
end

main

====================

The output is nothing ( it appears that the program hangs-on for a  
while ), then if go to the console and I push the ENTER key it appears  
the "Enter the number of employees: " and suddenly the program  
terminates.

What I’m doing wrong?, I tried to follow the instructions from several  
books ( David Black’s “Ruby for Rails” and Dave T. “Programming  
Ruby” ) and both indicates that the kind of code that I wrote should  
work.

Any help would be very appreciated.  
Regards

---

<div class="post-metadata">

**Author:** ![caof2005](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/97f17d/32.png) [@caof2005](https://www.ruby-forum.com/u/caof2005)\
**Post date:** [April 11, 2007, 9:25am UTC](https://www.ruby-forum.com/t/newbe-strange-behavior-of-print/91661/2 "2007-04-11T09:25:06Z")

</div>

caof2005 wrote:

> books ( David Black’s “Ruby for Rails” and Dave T. “Programming  
> Ruby” ) and both indicates that the kind of code that I wrote should  
> work.

Have you, per chance, tried to invoke your script from the command line?  
I know that SciTE needs to be patched in one way or another to allow for  
input. I can’t judge Eclipse in that regard, as I don’t use it.

–  
Phillip “CynicalRyan” Gawlowski  
[http://cynicalryan.110mb.com/](http://cynicalryan.110mb.com/)

Rule of Open-Source Programming #9:

Give me refactoring or give me death!

---

<div class="post-metadata">

**Author:** ![caof2005](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/97f17d/32.png) [@caof2005](https://www.ruby-forum.com/u/caof2005)\
**Post date:** [April 11, 2007, 11:31am UTC](https://www.ruby-forum.com/t/newbe-strange-behavior-of-print/91661/3 "2007-04-11T11:31:24Z")

</div>

On Apr 11, 2:24 am, Phillip G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > end  
> > What I’m doing wrong?, I tried to follow the instructions from several
> 
> Rule of Open-Source Programming #9:
> 
> Give me refactoring or give me death!

Phillip:

Yes I tried from within irb… and it works perfectly, however when I  
use either SciTE or EasyEclipse the behavior is awkward.

Regards  
Carlos

---

<div class="post-metadata">

**Author:** ![caof2005](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/97f17d/32.png) [@caof2005](https://www.ruby-forum.com/u/caof2005)\
**Post date:** [April 11, 2007, 11:43pm UTC](https://www.ruby-forum.com/t/newbe-strange-behavior-of-print/91661/4 "2007-04-11T23:43:45Z")

</div>

> Phillip:
> 
> Yes I tried from within irb… and it works perfectly, however when I  
> use either SciTE or EasyEclipse the behavior is awkward.
> 
> Regards  
> Carlos

Carlos -

I can’t speak to SciTE, but Eclipse (specifically with RDT) has an issue  
with the syncing of input/output.

See the first question at  
[Aptana.com | Axway](http://rubyeclipse.sourceforge.net/faq.rdt.html) for information about  
resolving the issue. Or just run from the command line.

---

<div class="post-metadata">

**Author:** ![caof2005](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/97f17d/32.png) [@caof2005](https://www.ruby-forum.com/u/caof2005)\
**Post date:** [September 25, 2007, 11:07pm UTC](https://www.ruby-forum.com/t/newbe-strange-behavior-of-print/91661/5 "2007-09-25T23:07:18Z")

</div>

On Apr 11, 3:36 am, Björn Paetzel [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > puts "The number of employees is:= " + numEmp.to\_s  
> > end
> 
> That should help. 🙂

Bjorn:

Thanks it worked great!  
However is it possible you can explain me in general terms why this  
behavior happens?  
I mean, besides trying in EasyEclipse and SciTE I tried the same code  
in irb, and surprisingly it works perfectly (no need to flush)!

Regards

---

<div class="post-metadata">

**Author:** ![caof2005](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/97f17d/32.png) [@caof2005](https://www.ruby-forum.com/u/caof2005)\
**Post date:** [September 25, 2007, 11:10pm UTC](https://www.ruby-forum.com/t/newbe-strange-behavior-of-print/91661/6 "2007-09-25T23:10:10Z")

</div>

On Wednesday 11 April 2007 09:25, caof2005 wrote:

> > > puts "The number of employees is:= " + numEmp.to\_s  
> > > in irb, and surprisingly it works perfectly (no need to flush)!
> 
> Regards

Irb have Readline support and also automatically flushes everything -  
just in  
case :] by deafault print don’t flush - if you want flushing - use puts
