Ruby wizardry, p.28
Ruby Wizardry, page 28
relationship, is-a, Inheritance and DRY Code
require method, Requiring Another File, Ruby and the Internet
require! method, You Know This!
return keyword, Defining Your Own Methods, return Versus puts, Splat Parameters, Simplifying Methods
vs. puts, Defining Your Own Methods
return value, return Versus puts, You Know This!
reverse method, A Short Yarn, A Bit More About Variables
rewind method, Writing and Adding to Files, Writing and Adding to Files, You Know This!
RSpec, Debugging
Rubular, Ruby Koans
'ruby' is not recognized ... error message, Installing on Mac or Linux
ruby command, When to Use IRB and When to Use a Text Editor
Ruby documentation, You Know This!, All Loading Docks, Report for Duty!
Ruby Koans, Ruby Tapas
Ruby Monk, Ruby Koans
Ruby on Rails, Advanced Books, Debugging
Ruby programming language, What This Book’s About, Why Learn Programming (and Why Ruby)?, Why Learn Programming (and Why Ruby)?, Installing on Mac or Linux, Installing on Mac or Linux, Using RubyInstaller, Achievement Unlocked: Ruby Installed!, Putting on the Ruby Slippers, Ruby and the Internet, Investigating the Kingdom’s Web Server, Beyond the Kingdom Walls, The Big Picture: What You Know, Installing on Mac, Installing on Mac
and Internet, Ruby and the Internet
converting to Python, Investigating the Kingdom’s Web Server, Beyond the Kingdom Walls
displaying version, Installing on Mac or Linux, Installing on Mac or Linux, Using RubyInstaller
in Mac or Linux, Installing on Mac or Linux
in Windows, Installing on Mac or Linux, Using RubyInstaller
history, Putting on the Ruby Slippers
installing, Why Learn Programming (and Why Ruby)?, Installing on Mac, Installing on Mac
on Linux, Installing on Mac
on Mac, Installing on Mac
interactive use, Achievement Unlocked: Ruby Installed!
reasons for learning, Why Learn Programming (and Why Ruby)?
resources, The Big Picture: What You Know
Ruby Rogues, Advanced Books
Ruby Tapas, Ruby Tapas
Ruby Weekly, Ruby Tapas
Ruby-to-Python project, Beyond the Kingdom Walls
Ruby5 podcast, Advanced Books
RubyGems website, Beyond the Kingdom Walls, You Know This!
RubyInstaller (Windows), Using RubyInstaller
running scripts, Creating Your First Script, The Apprentice Plumber’s Dilemma
RVM (Ruby Version Manager), Installing on Mac, Installing on Mac
S
sample method, Order Up!, Creating Modules
saving scripts, Using a Text Editor and the ruby Command
scope, Creating Our First Class, Minstrel, Variable Scope, Instance Variables, Objects and Classes, Looking Up Constants
modules, Looking Up Constants
top-level, Instance Variables
scope resolution operator (::), Looking Up Constants, You Know This!
screen, puts for printing to, return Versus puts
scripts, Putting on the Ruby Slippers, Getting to Know IRB, Using a Text Editor and the ruby Command, Creating Your First Script, When to Use IRB and When to Use a Text Editor, The Apprentice Plumber’s Dilemma, You Know This!, Classes and Objects, The Big Picture: What You Know
creating, Using a Text Editor and the ruby Command
name for, When to Use IRB and When to Use a Text Editor
running, Creating Your First Script, You Know This!
writing and running, The Apprentice Plumber’s Dilemma
secrecy.rb file, The Queen’s Machine
security, built-in methods for, The Queen’s Machine
self, Local Variables, Variables and Scope, Variables and Scope, The Big Picture: What You Know
and objects, Local Variables
displaying value, Variables and Scope
self.def method, Looking Up Constants
self.number_of_monkeys method, Variables and Scope
semicolon (;), to end line of code, Creating Modules
server.rb file, Investigating the Kingdom’s Web Server
shift method, Shift! Pop! Insert!, You Know This!
shovel operator (<<), Order Up!
shutdown, of web server, Investigating the Kingdom’s Web Server
Sinatra (program), Debugging
size method, You Know This!, The Subject of Our Story Is an Object
spaces, A Bit More About Variables, You Know This!, A Biggerish Project for You
and names, A Bit More About Variables, You Know This!
removing from input, A Biggerish Project for You
splat parameters, What Is nil?, Block Methods, You Know This!
and blocks, Block Methods
square brackets ([]), while Loops, You Know This!, You Know This!, You Know This!
for arrays, while Loops, You Know This!, You Know This!
for hash values, You Know This!
stories, A Short Yarn, Ruby Operators, The Apprentice Plumber’s Dilemma, Writing and Running Ruby Scripts, Ruby on Monorails, Big Hank’s Hashery, Hash in the Hashery, A Method to the Madness, Block Methods, The Subject of Our Story Is an Object, Methods and Instance Variables, Once More, with Feeling!, Utter Panda-monium, Refactoring at the Refactory, File Input and Output, Investigating the Kingdom’s Web Server
Apprentice Plumber’s Dilemma, The Apprentice Plumber’s Dilemma
Big Hank’s Hashery, Big Hank’s Hashery
Conclusion, Investigating the Kingdom’s Web Server
Dial-a-Ballad, or the Minstrel’s Delivery Service, Methods and Instance Variables
File Input and Output, File Input and Output
His Majesty’s Flow Control, Writing and Running Ruby Scripts
Into the Dagron’s Lair, Block Methods
King and His String, A Short Yarn, Ruby Operators
Method to the Madness, A Method to the Madness
Queen’s Machine, Once More, with Feeling!
Refactoring at the Refractory, Refactoring at the Refactory
Rollicking Ranges, Hash in the Hashery
Ruby on Monorails, Ruby on Monorails
Subject as Object, The Subject of Our Story Is an Object
Utter Panda-monium, Utter Panda-monium
storing hash, in variables, Hash in the Hashery
string interpolation, Writing and Running Ruby Scripts, You Know This!
strings, A Short Yarn, A Short Yarn, A Smallish Project for You, A Smallish Project for You, You Know This!, Writing and Running Ruby Scripts, You Know This!, Symbols!, Symbols and Hashes, Together at Last, You Know This!
#{} for inserting variable value into, Writing and Running Ruby Scripts, You Know This!
backward, A Smallish Project for You
changing to symbol, Symbols and Hashes, Together at Last
memory for, Symbols!
multiplying, A Smallish Project for You
quotation marks (“”) for, A Short Yarn
vs. symbols, You Know This!
strings_to_symbols.rb file, The Mid-morning Rush
subclass, Inheritance and DRY Code, You Know This!
Sublime Text 2, Using a Text Editor and the ruby Command
subtraction, Ruby Operators
super keyword, Overriding Methods: Pirates are People, Too, Every GuardDog Has His Day, You Know This!, You Know This!
superclass, Inheritance and DRY Code, You Know This!, You Know This!, You Know This!
sending right arguments to method, You Know This!
SuperSecretAccount class, inheritance by, The Queen’s Machine
symbols, Hash in the Hashery, Symbols!, Symbols!, Symbols!, The Skinny on Symbols, Symbols and Hashes, Together at Last, The Mid-morning Rush, You Know This!
additional features, The Mid-morning Rush
and hashes, The Skinny on Symbols
basics, Symbols!
changing strings to, Symbols and Hashes, Together at Last
memory for, Symbols!
vs. strings, You Know This!
syntax, Why Learn Programming (and Why Ruby)?
SyntaxError error, The Skinny on Symbols, Undefined Local Variable or Method
T
temporary variable, for array item, Putting Arrays and Loops into Action
Terminal application, Installing on Mac or Linux
ternary operator, Crystal-Clear Conditionals, De-duplicating Code, You Know This!
text editor, Getting to Know IRB, When to Use IRB and When to Use a Text Editor
vs. IRB program, When to Use IRB and When to Use a Text Editor
TextEdit (Mac), Using a Text Editor and the ruby Command
threads, Debugging
times method, Variable Scope
top-level scope, Instance Variables
to_a method, Rollicking Ranges, Order Up!, You Know This!
to_s method, What Else Can You Do with Symbols?, You Know This!
to_sym method, Symbols and Hashes, Together at Last, The Mid-morning Rush, What Else Can You Do with Symbols?, You Know This!
for strings, What Else Can You Do with Symbols?
troubleshooting, Troubleshooting
true, The Apprentice Plumber’s Dilemma, You Know This!
truthy values, Simplifying Methods, Simplifying Methods, You Know This!
TypeError error, Undefined Local Variable or Method
U
undefined local variable or method error, Undefined Local Variable or Method
underscore (_), A Bit More About Variables, Symbols!
in symbol names, Symbols!
unless statement, Improving flow_rate.rb with Fancier Logical Operators, You Know This!, What Is nil?, Variable Assignment Tricks, Variable Assignment Tricks, You Know This!
alternatives, You Know This!
else with, Variable Assignment Tricks
unshift method, Shift! Pop! Insert!, You Know This!
until, for while loop, while Loops
up arrow key, to go back to previous command, Go Back to a Previous Command
update_tally method, De-duplicating Code
V
values method, Hash in the Hashery, You Know This!
variables, A Short Yarn, A Short Yarn, You Know This!, You Know This!, Arrays, Hash in the Hashery, The Skinny on Symbols, What Else Can You Do with Symbols?, return Versus puts, Creating Our First Class, Minstrel, Creating Our First Class, Minstrel, Creating Our First Class, Minstrel, Variable Scope, Variable Scope, These Variable Errors Will Shock and Surprise You!, Global Variables, Instance Variables, Instance Variables, Objects and self, Methods and Instance Variables, Dial-a-Ballad, or the Minstrel’s Delivery Service, Objects and Classes, Objects and Classes, Variables and Scope, Variables and Scope, Refactoring at the Refactory, Refactoring at the Refactory, Variable Assignment Tricks
assignment tricks, Refactoring at the Refactory
class, Creating Our First Class, Minstrel, Global Variables, Dial-a-Ballad, or the Minstrel’s Delivery Service
conditional assignment of value to, Variable Assignment Tricks
default value for, Refactoring at the Refactory
errors, Variable Scope
global, These Variable Errors Will Shock and Surprise You!
inserting values into string, You Know This!
instance, Creating Our First Class, Minstrel, Instance Variables, Objects and self, Methods and Instance Variables, Variables and Scope, Variables and Scope
and methods, Objects and self
methods for reading and writing, Methods and Instance Variables
methods to see or change, Variables and Scope
local, Creating Our First Class, Minstrel, Instance Variables
names for, A Short Yarn
scope, Variable Scope, Objects and Classes
storing hashes in, Hash in the Hashery
storing symbols in, What Else Can You Do with Symbols?
storing values in, return Versus puts
temporary, Arrays
two different for same string value, The Skinny on Symbols
versions of Ruby, Installing on Mac or Linux, Installing on Mac or Linux, Using RubyInstaller
displaying in Mac or Linux, Installing on Mac or Linux
displaying in Windows, Installing on Mac or Linux, Using RubyInstaller
vertical pipe (|), in do/end, Putting Arrays and Loops into Action
videos, on Ruby, Ruby Tapas
W
'w' (write) mode, Writing and Adding to Files, All Loading Docks, Report for Duty!, You Know This!
web server, Investigating the Kingdom’s Web Server, Investigating the Kingdom’s Web Server, You Know This!
shutdown, Investigating the Kingdom’s Web Server
WEBrick, Beyond the Kingdom Walls, You Know This!, Debugging
shutdown, Beyond the Kingdom Walls
websites, Using the open-uri Ruby Gem, Beyond the Kingdom Walls, Debugging
built-in, Beyond the Kingdom Walls
creating, Debugging
opening, Using the open-uri Ruby Gem
web_server.rb file, Investigating the Kingdom’s Web Server
weezard.rb file, Global Variables
weezard_2.rb file, Instance Variables
when statement, When You Need a case Statement
while loop, Ruby on Monorails, while Loops, Your Project, Should You Choose to Accept It, You Know This!
end for, while Loops
Windows, Installing on Mac or Linux, Using a Text Editor and the ruby Command, Creating Your First Script
changing folder, Creating Your First Script
installing Ruby on, Installing on Mac or Linux
text editors for, Using a Text Editor and the ruby Command
Word (Microsoft), Using a Text Editor and the ruby Command
word processor, Using a Text Editor and the ruby Command
Y
yield keyword, Splat Parameters, You Know This!
Z
zero, and arrays, Shift! Pop! Insert!
Ruby Wizardry: An Introduction to Programming for Kids
Eric Weinstein
Copyright © 2014
RUBY WIZARDRY.
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher.
18 17 16 15 14 1 2 3 4 5 6 7 8 9
ISBN-10: 1-59327-566-8
ISBN-13: 978-1-59327-566-2
Publisher: William Pollock
Production Editor: Riley Hoffman
Cover Illustration: Karen Teixeira
Developmental Editor: Tyler Ortman
Technical Reviewers: Peter Cooper and Pat Shaughnessy
Copyeditor: Rachel Monaghan
Compositor: Riley Hoffman
Proofreader: Paula L. Fleming
Indexer: Nancy Guenther
For information on distribution, translations, or bulk sales, please contact No Starch Press, Inc. directly:
No Starch Press, Inc.
245 8th Street, San Francisco, CA 94103
phone: 415.863.9900; info@nostarch.com
www.nostarch.com
Library of Congress Control Number: 2014953112
No Starch Press and the No Starch Press logo are registered trademarks of No Starch Press, Inc. Other product and company names mentioned herein may be the trademarks of their respective owners. Rather than use a trademark symbol with every occurrence of a trademarked name, we are using the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.
The information in this book is distributed on an “As Is” basis, without warranty. While every precaution has been taken in the preparation of this work, neither the author nor No Starch Press, Inc. shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in it.
All characters in this publication are fictitious or are used fictitiously.
No Starch Press
2014-11-26T10:29:18-08:00
Eric Weinstein, Ruby Wizardry
