1. Trang chủ
  2. » Công Nghệ Thông Tin

Addison wesley the ruby way solutions and techniques in ruby programming 2nd edition nov 2006 ISBN 0672328844 (1)

1,3K 168 0

Đ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

Thông tin cơ bản

Định dạng
Số trang 1.325
Dung lượng 4,31 MB

Nội dung

The Ruby Way: Solutions and Techniques in Ruby Programming, Second Edition By Hal Fulton Publisher: Addison Wesley Professional Pub Date: October 25, 2006 Print ISBN-10: 0-672-32884-4 Print ISBN-13: 978-0-672-32884-8 Pages: 888 Table of Contents | Index Ruby is an agile object-oriented language, borrowing some of the best features from LISP, Smalltalk, Perl, CLU, and other languages Its popularity has grown tremendously in the five years since the first edition of this book The Ruby Way takes a "how-to" approach to Ruby programming with the bulk of the material consisting of more than 400 examples arranged by topic Each example answers the question "How do I do this in Ruby?" Working along with the author, you are presented with the task description and a discussion of the technical constraints This is followed by a step-by-step presentation of one good solution Along the way, the author provides detailed commentary and explanations to aid your understanding Coverage includes • An overview of Ruby, explaining terminology and basic principles • Operations on low-level data types (numbers, strings, regular expressions, dates) • The new regular expression engine (Oniguruma) • Internationalization (I18N) and message catalogs in Ruby • Operations on hashes, arrays, and other data structures such as stacks, trees, and graphs • Working with general I/O, files, and persistent objects • Database coverage including MySQL, SQLite, Oracle, DBI, and more • Ruby-specific techniques in OOP and dynamic programming • Graphical interfaces in Ruby (Tk, GTK+, Fox, and Qt) • Working with Ruby threads for lightweight multitasking • Everyday scripting and system administration in Ruby • Working with image files, PDFs, YAML, XML, RSS, and Atom • Testing, debugging, profiling, and packaging Ruby code • Low-level network programming and client-server interaction • Web development tools including Rails, Nitro, Wee, IOWA, and more • Working with distributed Ruby, Rinda, and Ring • Ruby development tools such as IDEs, documentation tools, and more The source code for the book can be downloaded from www.rubyhacker.com Hal Fulton has worked for over 15 years with variousforms of Unix, including AIX, Solaris, and Linux He was first exposed to Ruby in 1999, and in 2001 he began work on the first edition of this bookthe second Ruby book published in the English language He has attendednumerous Ruby conferences and has given presentations at several of those, including the first European Ruby Conference He has two degrees in computer science from the University of Mississippi and taught computer science for four years before moving to Austin, Texas to work as a contractor for variouscompanies, including IBM Austin Hal currently works at Broadwing Communications in Austin, Texas, maintaining a large data warehouse and related telecom applications, working daily with C++, Oracle, and, of course, Ruby The Ruby Way: Solutions and Techniques in Ruby Programming, Second Edition By Hal Fulton Publisher: Addison Wesley Professional Pub Date: October 25, 2006 Print ISBN-10: 0-672-32884-4 Print ISBN-13: 978-0-672-32884-8 Pages: 888 Table of Contents | Index Copyright Foreword Acknowledgments About the Author Introduction Chapter 1 Ruby in Review Section 1.1 An Introduction to Object Orientation Section 1.2 Basic Ruby Syntax and Semantics Section 1.3 OOP in Ruby Section 1.4 Dynamic Aspects of Ruby Section 1.5 Training Your Intuition: Things to Remember Section 1.6 Ruby Jargon and Slang Section 1.7 Conclusion Chapter 2 Working with Strings Section 2.1 Representing Ordinary Strings Section 2.2 Representing Strings with Alternate Notations Section 2.3 Using Here-Documents Section 2.4 Finding the Length of a String Section 2.5 Processing a Line at a Time Section 2.6 Processing a Byte at a Time Section 2.7 Performing Specialized String Comparisons Section 2.8 Tokenizing a String Section 2.9 Formatting a String Section 2.10 Using Strings As IO Objects Section 2.11 Controlling Uppercase and Lowercase Section 2.12 Accessing and Assigning Substrings Section 2.13 Substituting in Strings Section 2.14 Searching a String Section 2.15 Converting Between Characters and ASCII Codes Section 2.16 Implicit and Explicit Conversion Section 2.17 Appending an Item Onto a String Section 2.18 Removing Trailing Newlines and Other Characters Section 2.19 Trimming Whitespace from a String Section 2.20 Repeating Strings Section 2.21 Embedding Expressions Within Strings Section 2.22 Delayed Interpolation of Strings Section 2.23 Parsing Comma-Separated Data Section 2.24 Converting Strings to Numbers (Decimal and Otherwise) Section 2.25 Encoding and Decoding rot13 Text Section 2.26 Encrypting Strings Section 2.27 Compressing Strings Section 2.28 Counting Characters in Strings Section 2.29 Reversing a String Section 2.30 Removing Duplicate Characters Section 2.31 Removing Specific Characters Section 2.32 Printing Special Characters Section 2.33 Generating Successive Strings Section 2.34 Calculating a 32-Bit CRC Section 2.35 Calculating the MD5 Hash of a String Section 2.36 Calculating the Levenshtein Distance Between Two Strings Section 2.37 Encoding and Decoding base64 Strings Section 2.38 Encoding and Decoding Strings (uuencode/uudecode) Section 2.39 Expanding and Compressing Tab Characters Section 2.40 Wrapping Lines of Text Section 2.41 Conclusion Chapter 3 Working with Regular Expressions Section 3.1 Regular Expression Syntax Section 3.2 Compiling Regular Expressions Section 3.3 Escaping Special Characters Section 3.4 Using Anchors Section 3.5 Using Quantifiers Section 3.6 Positive and Negative Lookahead Section 3.7 Accessing Backreferences Section 3.8 Using Character Classes Section 3.9 Extended Regular Expressions Section 3.10 Matching a Newline with a Dot Section 3.11 Using Embedded Options Section 3.12 Using Embedded Subexpressions Section 3.13 Ruby and Oniguruma Section 3.14 A Few Sample Regular Expressions Section 3.15 Conclusion Chapter 4 Internationalization in Ruby Section 4.1 Background and Terminology Section 4.2 Coding in a Post-ASCII World Section 4.3 Using Message Catalogs Section 4.4 Conclusion Chapter 5 Performing Numerical Calculations Section 5.1 Representing Numbers in Ruby Section 5.2 Basic Operations on Numbers Section 5.3 Rounding Floating Point Values Section 5.4 Comparing Floating Point Numbers Section 5.5 Formatting Numbers for Output Section 5.6 Formatting Numbers with Commas Section 5.7 Working with Very Large Integers Section 5.8 Using BigDecimal Section 5.9 Working with Rational Values Section 5.10 Matrix Manipulation Section 5.11 Working with Complex Numbers Section 5.12 Using mathn Section 5.13 Finding Prime Factorization, GCD, and LCM Section 5.14 Working with Prime Numbers Section 5.15 Implicit and Explicit Numeric Conversion Section 5.16 Coercing Numeric Values Section 5.17 Performing Bit-level Operations on Numbers Section 5.18 Performing Base Conversions Section 5.19 Finding Cube Roots, Fourth Roots, and so on Section 5.20 Determining the Architecture's Byte Order Section 5.21 Numerical Computation of a Definite Integral Section 5.22 Trigonometry in Degrees, Radians, and Grads Section 5.23 More Advanced Trigonometry Section 5.24 Finding Logarithms with Arbitrary Bases Section 5.25 Finding the Mean, Median, and Mode of a Data Set Section 5.26 Variance and Standard Deviation Section 5.27 Finding a Correlation Coefficient Section 5.28 Generating Random Numbers Section 5.29 Caching Functions with memoize Section 5.30 Conclusion Chapter 6 Symbols and Ranges Section 6.1 Symbols Section 6.2 Ranges Section 6.3 Conclusion Chapter 7 Working with Times and Dates Section 7.1 Determining the Current Time Section 7.2 Working with Specific Times (Post-epoch) Section 7.3 Determining the Day of the Week Section 7.4 Determining the Date of Easter Section 7.5 Finding the Nth Weekday in a Month Section 7.6 Converting Between Seconds and Larger Units Section 7.7 Converting To and From the Epoch Section 7.8 Working with Leap Seconds: Don't! Section 7.9 Finding the Day of the Year Section 7.10 Validating a Date/Time Section 7.11 Finding the Week of the Year Section 7.12 Detecting Leap Years Section 7.13 Obtaining the Time Zone Section 7.14 Working with Hours and Minutes Only Section 7.15 Comparing Date/Time Values Section 7.16 Adding Intervals to Date/Time Values Section 7.17 Computing the Difference in Two Date/Time Values Section 7.18 Working with Specific Dates (Pre-epoch) Section 7.19 Interconverting Between Time, Date, and DateTime Section 7.20 Retrieving a Date/Time Value from a String Section 7.21 Formatting and Printing Date/Time Values Section 7.22 Time Zone Conversions Section 7.23 Determining the Number of Days in a Month Section 7.24 Dividing a Month into Weeks Section 7.25 Conclusion Chapter 8 Arrays, Hashes, and Other Enumerables Section 8.1 Working with Arrays Section 8.2 Working with Hashes Section 8.3 Enumerables in General Section 8.4 Conclusion Chapter 9 More Advanced Data Structures Section 9.1 Working with Sets Section 9.2 Working with Stacks and Queues Section 9.3 Working with Trees Section 9.4 Working with Graphs Section 9.5 Conclusion Chapter 10 I/O and Data Storage Section 10.1 Working with Files and Directories Section 10.2 Performing Higher-Level Data Access Section 10.3 Using KirbyBase Section 10.4 Connecting to External Databases Section 10.5 Conclusion Chapter 11 OOP and Dynamic Features in Ruby Section 11.1 Everyday OOP Tasks Section 11.2 More Advanced Techniques Section 11.3 Working with Dynamic Features Section 11.4 Conclusion Chapter 12 Graphical Interfaces for Ruby Section 12.1 Ruby/Tk Section 12.2 Ruby/GTK2 Section 12.3 FXRuby (FOX) Section 12.4 QtRuby Section 12.5 Other GUI Toolkits Section 12.6 Conclusion Chapter 13 Threads in Ruby Section 13.1 Creating and Manipulating Threads Section 13.2 Synchronizing Threads Section 13.3 Conclusion Chapter 14 Scripting and System Administration Section 14.1 Running External Programs Section 14.2 Command-Line Options and Arguments Section 14.3 The Shell Library Section 14.4 Accessing Environment Variables Section 14.5 Scripting in Microsoft Windows Section 14.6 The Windows One-Click Installer Section 14.7 Libraries You Need to Know About Section 14.8 Working with Files, Directories, and Trees Section 14.9 Miscellaneous Scripting Tasks Section 14.10 Conclusion Chapter 15 Ruby and Data Formats Section 15.1 Parsing XML with REXML Section 15.2 Working with RSS and Atom Section 15.3 Manipulating Image Data with RMagick Section 15.4 Creating PDF Documents with PDF::Writer Section 15.5 Conclusion Chapter 16 Testing and Debugging Section 16.1 Testing with Test::Unit Section 16.2 The ZenTest Tools Section 16.3 Using the Ruby Debugger Section 16.4 Using irb As a Debugger Section 16.5 Measuring Code Coverage Section 16.6 Measuring Performance Section 16.7 Prettyprinting Objects Section 16.8 Conclusion Chapter 17 Packaging and Distributing Code Section 17.1 Using RDoc Section 17.2 Installation and Packaging Section 17.3 RubyForge and the RAA Section 17.4 Conclusion Chapter 18 Network Programming Section 18.1 Network Servers Section 18.2 Network Clients Section 18.3 Conclusion Chapter 19 Ruby and Web Applications Section 19.1 CGI Programming with Ruby Section 19.2 Using FastCGI Section 19.3 Ruby on Rails Section 19.4 Web Development with Nitro Section 19.5 An Introduction to Wee Section 19.6 Web Development with IOWA Section 19.7 Ruby and the Web Server Section 19.8 Conclusion Chapter 20 Distributed Ruby Section 20.1 An Overview: Using drb Section 20.2 Case Study: A Stock Ticker Simulation Section 20.3 Rinda: A Ruby Tuplespace Section 20.4 Service Discovery with Distributed Ruby Section 20.5 Conclusion Chapter 21 Ruby Development Tools Section 21.1 Using RubyGems Section 21.2 Using Rake Section 21.3 Using irb Section 21.4 The ri Utility Section 21.5 Editor Support Section 21.6 Integrated Development Environments Section 21.7 Conclusion Chapter 22 The Ruby Community Section 22.1 Web Resources Section 22.2 Newsgroup and Mailing Lists Section 22.3 Blogs and Online Magazines Section 22.4 Ruby Change Requests Section 22.5 IRC Channels Section 22.6 Ruby Conferences Section 22.7 Local Ruby Groups Section 22.8 Conclusion Index Copyright 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 publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals The author and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein The publisher offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales, which may include electronic versions and/or custom covers and content particular to your business, training goals, marketing focus, and branding interests For more information, please contact: U.S Corporate and Government Sales (800) 382-3419 corpsales@pearsontechgroup.com For sales outside the United States please contact: International Sales international@pearsoned.com Visit us on the Web: www.awprofessional.com Library of Congress Cataloging-in-Publication Data: Fulton, Hal Edwin, 1961- mbchar? convenience method methods, special characters in precomposed/decomposed forms table regular expressions 2nd string concatenation of string interpretation substrings, checking for unaccented characters unpack method unimodal data sets uninitialized objects union method, mathematical sets unit tests (Ruby on Rails) unit_diff program (ZenTest tools) unless statements unless-else clauses unlinking files unpack method binary files strings, I18N until control structures until loops do keyword nil values update method updating files GUI state, FXRuby messages, message catalogs web pages, Nitro upto method, generating successive strings URLs retrieving web pages from state, associating with (Wee) user groups (Ruby) user ID (files) UTC (Coordinated Universal Time) 2nd UTF-16 (Unicode encodings) UTF-8 (Unicode encodings) $KCODE global variable bytes, character correspondences character encodings converting detecting decomposed characters jcode library 2nd jcount method mbchar? convenience method methods, special characters in precomposed/decomposed forms table regular expressions 2nd strings bracket notations concatenation of interpretation in iterating over substrings, checking for unaccented characters unpack method utime method, file time stamps uudecode utility, strings uuencode utility, strings Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] validating dates/time value method, threads variables [See also symbols, converting to strings.] $&, string substitutions $flag, threads $KCODE $MATCH, string substitutions $SAFE, threads @@ prefix arrays assigning values to class creating lists of, obtaining class instance 2nd classes condtion, threads declaring environment getting importing as globals message catalogs setting storing as arrays storing as hashes err, exceptions Fahrenheit and Celsius temperature conversion sample program global $stdout aliases examples of hashes instance assigning class instances examples of lists, obtaining retrieving interpolation local examples of object variables versus method names versus modifying objects 2nd pseudovariables examples of self swapping threads accessing from scope accessing in variance (data sets) vectors vim Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] wakeup method, awakening threads wday instance method, determining days of the week web applications CGI programming Amrita Cerise cgi.rb library cookies displaying/processing HTML forms ruby-web URL access user sessions FastCGI IOWA app.cnf configuration file component control transfer home page installing mapfile.cnf configuration file mixed HTML/component templates oid variable requests templating in tracking session state Nitro Ajax support basic applications, creating caching action compiler pipelines controller classes defining locales DHTML support Elements MVC design pattern Og page requests parts template content substitution updating web pages web resources Ruby on Rails breakpointers core extensions fixtures InstantRails Locomotive mock objects MVC design pattern plugins RadRails scaffolding testing/debugging applications TextMate time operations Wee associating state with URLs automatic file reloading components defining HTML simple example of Web resources web development IOWA app.cnf configuration file component control transfer home page installing mapfile.cnf configuration file mixed HTML/component templates oid variable requests templating in tracking session state Nitro Ajax support basic applications, creating caching actions compiler pipelines controller classes defining locales DHTML support Elements MVC design pattern Og page requests parts template content substitution updating web pages web resources web pages retrieving from URLs updating, Nitro web servers erb mod_ruby Mongrel WEBrick Wee (Web Engineering Easy) automatic file reloading components HTML, defining simple example of URLs, association state with Web resources weeks day of the week, determining dividing months into Nth weekday in a month, finding week of the year, finding when clauses [See case statements, case limbs.] while control structures while loops do keyword nil values whitespace, trimming from strings Win32API, scripting in Microsoft Windows Win32OLE, scripting in Microsoft Windows windowed application examples FXRuby QtRuby Ruby/GTK2 Ruby/Tk Windows (Microsoft) one-click installers scripting in ActiveScriptRuby Win32API Win32OLE Windows API word boundaries wrapping text, strings writable_real? method, file ownership writer attributes writer/reader attributes wxWidgets Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] X Window System XML, parsing XOR ( ^ ) operator, number bit-level operations XP (Extreme Programming) XPath, REXML data format Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] YAML (YAML Ain't Markup Language) years day of, finding leap years, finding week of, finding yield keyword 2nd Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] ZenTest tools autotest tool command-line switches CUT multiruby tool unit_diff program zero method, matrices zero-length matches, regular expressions zero-width assertions zero? method ZIP Codes, matching (regex) Zlib method, compressing strings zone accessor, finding time zones ... applications, working daily with C++, Oracle, and, of course, Ruby The Ruby Way: Solutions and Techniques in Ruby Programming, Second Edition By Hal Fulton Publisher: Addison Wesley Professional Pub Date: October 25, 2006 Print ISBN- 10: 0-672-32884-4... Fulton, Hal Edwin, 1961- The Ruby way : solutions and techniques in Ruby programming / Hal Fulto - 2nd ed p cm Includes index ISBN 0-672-32884-4 (pbk : alk paper) 1 Objectoriented programming (Computer science) 2... Everyday scripting and system administration in Ruby • Working with image files, PDFs, YAML, XML, RSS, and Atom • Testing, debugging, profiling, and packaging Ruby code • Low-level network programming and client-server interaction

Ngày đăng: 26/03/2019, 17:06

TỪ KHÓA LIÊN QUAN