Programming Ruby 1.9: The Pragmatic Programmers' Guide (Facets of Ruby)

Programming Ruby 1.9: The Pragmatic Programmers' Guide (Facets of Ruby)

Dave Thomas, Chad Fowler

Language: English

Pages: 864

ISBN: 1934356085

Format: PDF / Kindle (mobi) / ePub


Would you like to go from first idea to working code much, much faster? Do you currently spend more time satisfying the compiler instead of your clients or end users? Are you frustrated with demanding languages that seem to get in your way, instead of getting the work done? Are you using Rails, and want to dig deeper into the underlying Ruby language? If so, then we've got a language and book for you!

Ruby 1.9 is the latest version of Ruby. It has many compelling features, including multinationalization support, new block scoping, and better performance. At the same time, the current Ruby 1.8 is still being maintained and is widely used. We're therefore releasing both the Ruby 1.9 version of the PickAxe (this book) alongside the 1.8 version of the PickAxe. Readers can choose the book that matches their environment.

Ruby is a fully object-oriented language, much like the classic object-oriented language, Smalltalk. Like Smalltalk, it is dynamically typed (as opposed to Java or C++), but unlike Smalltalk, Ruby features the same conveniences found in modern scripting languages, making Ruby a favorite tool of intelligent, forward-thinking programmers and the basis for the Rails web framework.

This is the reference manual for Ruby, including a description of all the standard library modules, a complete reference to all built-in classes and modules (including all the new and changed methods introduced by Ruby 1.9). It also includes all the new and changed syntax and semantics introduced since Ruby 1.8. Learn about the new parameter passing rules, local variable scoping in blocks, fibers, multinationalization, and the new block declaration syntax, among other exciting new features.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308 308 308 310 317 319 329 336 339 342 343 345 346 347 351 353 Duck Typing 23.1 Classes Aren’t Types . . . . . . . 23.2 Coding like a Duck . . . . . . . . 23.3 Standard Protocols and Coercions 23.4 Walk the Walk, Talk the Talk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

ObjectSpace, and Distributed Ruby 25.1 Looking at Objects . . . . . . . . . . . . 25.2 Looking at Classes . . . . . . . . . . . . 25.3 Calling Methods Dynamically . . . . . . 25.4 System Hooks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402 402 404 405 407 23 24 25 307 . . . . . . . . Report erratum Prepared exclusively for Ian MacLeod this copy is (3.0

as $3. Pattern-Based Substitution We’ve already seen how sub and gsub replace the matched part of a string with other text. In those previous examples, the pattern was always fixed text, but the substitution methods work equally well if the pattern contains repetition, alternation, and grouping. a = "quick brown fox" a.sub(/[aeiou]/, '*') a.gsub(/[aeiou]/, '*') a.sub(/\s\S+/, '') a.gsub(/\s\S+/, '') # # # # => => => => "q*ick brown fox" "q**ck br*wn f*x" "quick fox" "quick" The substitution

least one time, regardless of the value of the boolean expression: print "Hello\n" while false begin print "Goodbye\n" end while false produces: Goodbye Iterators If you read the beginning of the previous section, you may have been discouraged. “Ruby has pretty primitive built-in looping constructs,” it said. Don’t despair, gentle reader, for we have good news. Ruby doesn’t need any sophisticated built-in loops, because all the fun stuff is implemented using Ruby iterators. For example, Ruby

The Pragmatic Bookshelf™ is an imprint of The Pragmatic Programmers, LLC.
Copyright © 1999–2010 The Pragmatic Programmers, LLC. All Rights Reserved.

Second hyperlink is Connect! Hpricot can also update and create HTML. It’ll even try to fix up bad HTML. And if Hpricot doesn’t work for you, the nokogiri gem is an even more sophisticated HTML and XML parser. 3. Install it using

Download sample

Download