Ruby For Kids For Dummies
Published by: John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030-5774, www.wiley.com
Copyright 2016 by John Wiley & Sons, Inc., Hoboken, New Jersey
Published simultaneously in Canada
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without the prior written permission of the Publisher. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions
.
Trademarks: Wiley, For Dummies, the Dummies Man logo, Dummies.com, Making Everything Easier, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc., and may not be used without written permission. All other trademarks are the property of their respective owners. John Wiley & Sons, Inc., is not associated with any product or vendor mentioned in this book.
LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY : WHILE THE PUBLISHER AND AUTHOR HAVE USED THEIR BEST EFFORTS IN PREPARING THIS BOOK, THEY MAKE NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS BOOK AND SPECIFICALLY DISCLAIM ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES REPRESENTATIVES OR WRITTEN SALES MATERIALS. THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR YOUR SITUATION. YOU SHOULD CONSULT WITH A PROFESSIONAL WHERE APPROPRIATE. NEITHER THE PUBLISHER NOR THE AUTHOR SHALL BE LIABLE FOR DAMAGES ARISING HEREFROM.
For general information on our other products and services, please contact our Customer Care Department within the U.S. at 877-762-2974, outside the U.S. at 317-572-3993, or fax 317-572-4002. For technical support, please visit www.wiley.com/techsupport
.
Wiley publishes in a variety of print and electronic formats and by print-on-demand. Some material included with standard print versions of this book may not be included in e-books or in print-on-demand. If this book refers to media such as a CD or DVD that is not included in the version you purchased, you may download this material at http://booksupport.wiley.com
. For more information about Wiley products, visit www.wiley.com
.
Library of Congress Control Number: 2015941961
ISBN 978-1-119-05590-7 (pbk); ISBN 978-1-119-05599-0 (ebk); ISBN 978-1-119-05600-3
Ruby For Kids For Dummies
Visit www.dummies.com/cheatsheet/rubyforkids to view this book's cheat sheet.
- Table of Contents
Guide
Pages
Introduction
Ruby For Kids For Dummies is an introduction to the basics of coding using the Ruby programming language. In each chapter, I walk you through a step-by-step set of instructions to create a Ruby program for your Mac or Windows computer. You dont need to have any programming experience to understand this book, but you do need to have a sense of curiosity and adventure!
The Ruby programming language has been around since the mid-1990s and has become very popular with web application programmers. It can be used for so much more than just web apps. In this book, youll see that you can use Ruby for small command line tools and calculations; larger programs for home, work, or school; or even graphical games (and Ill show you a lot of games).
Ruby was designed by its creator Yukihiro Matsumoto to be both fun and productive. My hope is that as you explore the projects in this book, youll definitely have fun and be inspired to continue to use Ruby (or any other programming language) to realize your own coding ideas.
Programming in general is similar to sports, music, or even creative arts. Its hard to just absorb a book on the subject and expect to understand it completely or start to gain mastery of the topic. Instead, you need to have keyboard time and practice. Even professional coders continue to practice throughout their careers.
By exploring and playing around with the projects here, youll be taking the first steps down a really interesting Ruby-colored road.
About This Book
Programming is a large topic, and Ruby itself is a very powerful language. Ill be working to shed light on some of the more fundamental parts of Ruby and coding in general. There is no rush to finish the projects in the book. Go through each Ruby For Kids For Dummies project as quickly or slowly as you like. Each chapters project is a self-contained useful utility or fun game. Along the way, youll learn how to use the very same tools that the professionals use, and learn the kinds of techniques that will help you grow as a programmer.
You dont need to have any previous programming experience, but if you know a little, thats fine youll pick up how Ruby does things and also see some similarities to other languages. Ill show you the Ruby way when applicable, but Ill also show the easy way when youre just learning the concepts.
Topics covered in this book include the following:
- The general way to structure simple Ruby programs
- Ruby expressions and operators
- Organizing functionality using methods and objects
- Basic ways to represent data like numbers, strings, and arrays
- Using loops
- Making choices with ifelse statements
Learning to program with Ruby isnt just about writing code in the language. You also need to learn about the tools, resources, and community that stand behind the language.
Ruby has become so popular because its a relatively simple language to learn, and the tools needed to write Ruby, test it, and run it are widely available and free. In this book, I help you get started with just a few basic, free, programs that do everything you need to create some pretty sophisticated pieces of software.
Youll also learn about general programming techniques, and most important, see a wide variety of projects that will pique your interest and hopefully encourage you to take your exploration to the next level.
To make this book easier to read, youll want to keep in mind a few tips. First, all Ruby code and all terminal commands appear in monospaced type like this:
puts "hello programs! Welcome to Ruby"
The margins on a book page dont have the same room as your monitor likely does, so long lines of Ruby and any output it creates may break across multiple lines. Remember that your computer sees such lines as a single line of Ruby. I show that everything should be on one line by breaking it at a punctuation character or space and then indenting any overage, like so:
def room_type
["cave", "treasure room", "rock cavern", "tomb", "guard room", "lair"].sample
end
Ruby is case sensitive, which means that swapping the use of uppercase or lowercase letters or a combination of the two can break things. In order to make sure that you get the correct results from the projects in the book, always stick to the same capitalization and spelling that I use.
Ruby also cares about the kind of quotation marks that you use! So, if you see double quotes ( " ) or single quotes ( ' ), be sure to use what I show and make sure theyre straight and not curly.
Next page