Learn to Program, Second Edition (The Facets of Ruby Series)
Format: PDF / Kindle (mobi) / ePub
Printed in full color.
For this new edition of the best-selling Learn to Program, Chris Pine has taken a good thing and made it even better. First, he used the feedback from hundreds of reader e-mails to update the content and make it even clearer. Second, he updated the examples in the book to use the latest stable version of Ruby, and also to use code that looks more like real-world Ruby code, so that people who have just learned to program will be more familiar with common Ruby techniques.
Not only does the Second Edition now include answers to all of the exercises, it includes them twice. First you'll find the "how you could do it" answers, using the techniques you've learned up to that point in the book. Next you'll see "how Chris Pine would do it": answers using more advanced Ruby techniques, to whet your appetite as well as providing sort of a "Rosetta Stone" for more elegant solutions.
Computers are everywhere, on every desk, in your iPod, cell phone, and PDA. To live well in the 21st century, you need to know how to make computers do things. And to really make computers do what you want, you have to learn to program.
Fortunately, that's easier now than ever before. Chris Pine's book will teach you how to program. You'll learn to use your computer better, to get it to do what you want it to do. Starting with small, simple one-line programs to calculate your age in seconds, you'll see how to advance to fully structured, real programs. You'll learn the same technology used to drive modern dynamic websites and large, professional applications.
It's now easier to learn to write your own computer software than it has ever been before. Now everyone can learn to write programs for themselves---no previous experience is necessary. Chris takes a thorough, but light-hearted approach that teaches you how to program with a minimum of fuss or bother.
Printed in full color.
Learn to Program Chris Pine The Pragmatic Bookshelf Raleigh, North Carolina Dallas, Texas P r a g m a t i c B o o k s h e l f Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and The Pragmatic Programmers, LLC was aware of a trademark claim, the designations have been printed in initial capital letters or in all capitals. The Pragmatic Starter Kit, The
remember where to find out about them (and that would be right here). Let’s look at to_s and join. join works much like to_s does, except that it adds a string in between the array’s objects. Actually, I can’t think of a time when I have ever used to_s. I always use puts or join. But I know you’re dying to know how to_s works, so have a look at the following example. Report erratum MORE ARRAY METHODS 62 foods = [' artichoke' , ' brioche' , ' caramel' ] puts foods puts puts foods.to_s
points to the parameter passed in. So if I type say_moo 3, then the parameter is 3, and the variable number_of_moos points to 3. As you can see, the parameter is now required. After all, what is say_moo supposed to multiply 'mooooooo...' by if you don’t give it a parameter? Your poor computer has no idea. If objects in Ruby are like nouns in English and methods are like verbs, then you can think of parameters as adverbs (like with say_moo, where the parameter told us how to say_moo) or
one is trickier.... How can you test to make sure you are getting a perfect shuffle? What would you even say a perfect shuffle would be? Now test for it. • Your sorting algorithm is pretty good, sure. But there was always that sort of embarrassing point you were hoping I’d just sort of gloss over, right? About the capital letters? Your sorting algorithm is good for general-purpose sorting, but when you sort strings, you are using the ordering of the characters in your fonts (called the
an object (called a proc), store it in a variable or pass it to a method, and run the code in the block whenever you feel like (more than once, if you want). So it’s kind of like a method itself, except it isn’t bound to an object (it is an object), and you can store it or pass it around like you can with any object. I think it’s example time: toast = Proc.new do puts ' Cheers!' end toast.call toast.call toast.call Cheers! Cheers! Cheers! So I created a proc (which I think is