# How to 'space' certain things apart?

**URL:** <https://www.ruby-forum.com/t/how-to-space-certain-things-apart/89827>\
**Category:** Ruby\
**Created:** [March 29, 2006, 9:59am UTC](https://www.ruby-forum.com/t/how-to-space-certain-things-apart/89827 "2006-03-29T09:59:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 29, 2006, 9:59am UTC](https://www.ruby-forum.com/t/how-to-space-certain-things-apart/89827/1 "2006-03-29T09:59:01Z")

</div>

Hi,

I’m trying to learn a programming language and this one came up in my  
searches as a fairly easy one. I’ve never taken any courses and have  
absolutely zero knowledge of programming or scripting. The main reason I  
want  
to learn a language is just to simply make my own scripts for a MUD I  
play  
online, heh.

Anyway, I found a place to at least get me started and I had to do  
this  
program below. The problem I’m having is that at the end, it shows the  
persons name as, example: JimmySBrown instead of Jimmy S Brown. How do I  
get  
it to add the two spaces I need?

puts ‘Please tell me your first name.’  
first\_name = gets.chomp  
puts ‘Please tell me your middle initial.’  
middle\_initial = gets.chomp  
puts ‘Please tell me your last name now.’  
last\_name = gets.chomp  
var1 = first\_name  
var2 = middle\_initial  
var3 = last\_name  
name = var1.to\_s + var2.to\_s + var3.to\_s  
puts 'Pleased to meet you, ’ + name + ‘!’

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 29, 2006, 10:14am UTC](https://www.ruby-forum.com/t/how-to-space-certain-things-apart/89827/2 "2006-03-29T10:14:26Z")

</div>

1. you don’t need extra variables var, var2, var2 - you already have  
all required values in variables first\_name, middle\_initial,  
last\_name;
2. value stored in var1 varable is already a String - don’t need to  
convert it with var1.to\_s;
3. to build name value you can use:  
name = first\_name + ’ ’ + middle\_initial + ’ ’ + last\_name  
or  
name = “#{first\_name} #{middle\_initial} #{last\_name}”  
or  
name = format( “%s %s %s”, first\_name, middle\_initial, last\_name )  
or (same as previous)  
name = “%s %s %s” % [first\_name, middle\_initial, last\_name]

don’t be confused by so many ways to make it, just pick one and use it;  
happy rubying!

Sergey

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 29, 2006, 10:15am UTC](https://www.ruby-forum.com/t/how-to-space-certain-things-apart/89827/3 "2006-03-29T10:15:12Z")

</div>

JB wrote:

> persons name as, example: JimmySBrown instead of Jimmy S Brown. How do I get  
> var3 = last\_name  
> name = var1.to\_s + var2.to\_s + var3.to\_s  
> puts 'Pleased to meet you, ’ + name + ‘!’

You picked a good starter language to learn!

No need to create those extra vars:

name = “#{first\_name} #{middle\_initial} #{last\_name}”

Note the spaces put in between the values.

Cheers

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 29, 2006, 11:34am UTC](https://www.ruby-forum.com/t/how-to-space-certain-things-apart/89827/4 "2006-03-29T11:34:08Z")

</div>

ChrisH wrote:

Thanks CrisH and vsv. That got me through it better.
