everyday scripting with ruby, the pragmatic programers (2006)

297 390 0
everyday scripting with ruby, the pragmatic programers (2006)

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

[...]... Ruby [TH01] It’s also from the Pragmatic Bookshelf—indeed, Dave is one of the owners of the press But I’m not recommending their book because they’re my publisher They’re my publisher because I kept recommending their book 1.3 Service After the Sale Everyday Scripting with Ruby has its very own Pragmatic Programmers’ web page at http://www.pragmaticprogrammer.com/titles/bmsft/ There, you will find updates,... I build the first two projects slowly, showing and explaining all my work You’ll learn best if you type along with me, building the project as we go In the third and fourth projects, I move faster and explain only the finished result The practice files that come with the book contain a series of snapshots for each of the first two projects The snippets of Ruby code in the book identify the file they come... Unzipping the file creates a folder named code I recommend renaming that to something more specific, like scripting- book, but I’ll use code to refer to it throughout the book 1 The command-line interpreter will be explained shortly I N THE B EGINNING WAS THE C OMMAND L INE 20 Within code, there is a subfolder for each of the scripts in the book Do your work within those subfolders There’s also a subfolder with. .. back to the editor, correct the mistake, and repaste it than it is to fool around with the arrow keys On the Mac and other Unix-like systems, the cut, copy, and paste keystrokes work as you’d expect For example, on the Mac, D V pastes into the Terminal window In that window, you can select a range of text, copy it with D C, and then paste it into an editor window On Windows, you’ll paste to the command... command line with a right click rather than the normal Ctrl + V Alternately, you can use an Edit menu that you get by right-clicking the title bar To copy from the Windows command line, select text with the mouse, and then press Enter If that doesn’t work, make sure you have “quick edit” turned on Open the Properties dialog (via the control menu you get with Alt + Space or by right-clicking in the title... continuation prompt strings 27 I T ’ S T IME TO M AKE M ISTAKES the other irb will dutifully do what you don’t want: include what you thought was the ending character in the string and then give you a prompt to end the string You have two options One is to end the string with the appropriate character and then type the correct string at the next noncontinuation prompt: irb(main):014:0* 'a string " irb(main):015:0'... that receives the message as irb itself When you run a Ruby script from the command line, it would be the script itself Another reason puts looks odd is that there are no parentheses around its single argument You can leave parentheses off if Ruby knows where you would have put them receiver 35 M AKING A S CRIPT — The string is printed to the screen This printing has nothing to do with the way irb prints... now finished" Notice that the result string has something odd in the middle The \n shows that an end-of-line character is treated like all the others when it’s typed into the unclosed string: it’s included in the result (The endof-line character is either Enter or Return , depending on whether you use Windows, Mac OS X, etc.) That’s nice when you want such a character in the string When it’s because... as their children were born, grew up, left home, got married, and had children of their own—all during the writing of this book And I’d like to thank my family You wouldn’t believe what they’ve let me get away with 18 Chapter 2 Getting Started This chapter gets you ready for the rest of the book • Everyone will need to download the practice files • If you’re not familiar with the command line ( the. .. contain letters, numbers, and the underscore character (not a hyphen) Names can’t begin with a number, nor may they include spaces Case matters: my_ship is not the same name as my_Ship If everything in Ruby is objects, messages, and names, where’s the message send here? You can read the line as “send the array named old_inventory the message named ‘-’ with the argument being the array named by new_inventory.” . letters or in all capitals. The Pragmatic Starter Kit, The Pragmatic Programmer, Pragmatic Programming, Prag matic Bookshelf and the linking g device are trademarks of The Pragmatic Programmers, LLC. Every. each of the scripts in the book. Do your work within those subfolders. There’s also a subfolder with solu- tions t o the exercises and several subfolders with more Ruby examples. 2.2 In the B eginning. snapshots p r actice files for each of the first two projects. The snippets of Ruby code in the book identify the file they come from. You can look at the file to see the snippet in context, to diagnose

Ngày đăng: 29/04/2014, 14:42

Từ khóa liên quan

Mục lục

  • Contents

  • Introduction

    • How the Book Works

    • An Outline of the Book

    • Service After the Sale

    • Supplements

    • Acknowledgments

    • Getting Started

      • Download the Practice Files

      • In the Beginning Was the Command Line

      • Do You Need to Install Ruby?

      • Installing Ruby

      • Your Two Basic Tools

      • Prompts, Command Lines, Prompts, and irb

      • It's Time to Make Mistakes

      • The Basics

        • A First Script: Comparing File Inventories

          • A Script in Action

          • The Ruby Universe

          • Objects Send and Receive Messages

          • Variables Name Objects

          • Comparing Arrays

          • Printing to the Screen

          • Making a Script

Tài liệu cùng người dùng

Tài liệu liên quan