From: Panagiotis Atmatzidis Date: 2012-07-09T06:07:16+09:00 Subject: Re: How to Print on a single line Hello, On 8 Ιουλ 2012, at 22:18 , Kareem Adams wrote: > Hi there, > > How do I get the below script to print the 2nd part on a single line? > > print 'Hello there, and what\'s your name? ' > name = gets > puts 'Your name is ' + name + '? What a lovely name!' Your problem is on gets which needs to be turned into gets.chomp (as already addressed earlier). There are several ways to print lines into ruby. If you are more accustomed to 'C' or if you need more flexibility you can print using printf and sprintf[1]. Also you can use just 'p'. Take a look at the example below: ------- GreyJewel:~ atma$ irb 1.9.2p320 :001 > array = %w( a b c d e f g ) => ["a", "b", "c", "d", "e", "f", "g"] 1.9.2p320 :002 > puts array a b c d e f g => nil 1.9.2p320 :003 > p array ["a", "b", "c", "d", "e", "f", "g"] => ["a", "b", "c", "d", "e", "f", "g"] 1.9.2p320 :004 > printf("First letter:\t %s\n", array[0]) First letter: a => nil 1.9.2p320 :005 > quit GreyJewel:~ atma$ -------------- Note that using printf I was able to add a tab using '\t' and a new line using '\n'. Take a look at [2] for more info. Happy rubying :-) [1] http://www.ruby-doc.org/docs/ruby-doc-bundle/Manual/man-1.4/function.html#sprintf [2] http://en.wikipedia.org/wiki/Printf_format_string Panagiotis Atmatzidis ----------------------------- Pharmacy Student at VFU email4lists: ml@convalesco.org More info: http://about.me/atmosx The wise man said: "Never argue with an idiot, he brings you down to his level and beat you with experience."