Skip to Main Content
Learn to Program, 2nd Edition
book

Learn to Program, 2nd Edition

by Chris Pine
March 2009
Intermediate to advanced content levelIntermediate to advanced
194 pages
4h
English
Pragmatic Bookshelf
Content preview from Learn to Program, 2nd Edition

Exercises from Chapter 5

Full Name Greeting

How you could do it:

puts ​'What is your first name?'
f_name = gets.chomp
puts ​'What is your middle name?'
m_name = gets.chomp
puts ​'What is your last name?'
l_name = gets.chomp
full_name = f_name + ​' '​ + m_name + ​' '​ + l_name
puts ​'Hello, '​ + full_name + ​'!'
<= What is your first name?
=> Sam
<= What is your middle name?
=> I
<= What is your last name?
=> Am
<= Hello, Sam I Am!

How I would do it:

puts ​"What's your first name?"
f_name = gets.chomp
puts ​"What's your middle name?"
m_name = gets.chomp
puts ​"What's your last name?"
l_name = gets.chomp
puts ​"Chris Pine is cooler than you, ​#{f_name}​ ​#{m_name}​ ​#{l_name}​."
<= What's your first name?
=> Marvin
<= What's your middle name?
=> K.
<= ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learn to Program, 3rd Edition

Learn to Program, 3rd Edition

Chris Pine
The Book of Ruby

The Book of Ruby

Huw Collingbourne

Publisher Resources

ISBN: 9781680500172Errata