Annotation Everyone in the Ruby world seems to be talking about metaprogramming--how you can use it to remove duplication in your code and write elegant, beautiful programs. Now you can get in on the action as well. This book describes metaprogramming as an essential component of Ruby. Once you understand the principles of Ruby, including the object model, scopes, and eigenclasses, you're on your way to applying metaprogramming both in your daily work and in your fun, after-hours projects. Learning metaprogramming doesn't have to be difficult or boring. By taking you on a Monday-through-Friday workweek adventure with a pair of programmers, Paolo Perrotta helps make mastering the art of metaprogramming both straightforward and entertaining. The book is packed with: Pragmatic examples of metaprogramming in action, many of which come straight from popular libraries or frameworks, such as Rails. Programming challenges that let you experiment and play with some of the most fun, "out-there" metaprogramming concepts. Metaprogramming "spells"--34 practical recipes and idioms that you can study and apply right now, to write code that is sure to impress. Whether you're a Ruby apprentice on the path to mastering the language or a Ruby wiz in search of new tips, this book is for you.
Program Like the Ruby Pros
Author: Paolo Perrotta
Provides information on metaprogramming concepts to help write productive Ruby code.
Program Like the Ruby Pros
Author: Paolo Perrotta
"An under-the-hood look at how the Ruby programming language runs code. Extensively illustrated with complete explanations and hands-on experiments. Covers Ruby 2.x"--
Learning Ruby Internals Through Experiment
Author: Pat Shaughnessy
Publisher: No Starch Press
Get ready to see Rails as you've never seen it before. Learn how to extend the framework, change its behavior, and replace whole components to bend it to your will. Eight different test-driven tutorials will help you understand Rails' inner workings and prepare you to tackle complicated projects with solutions that are well-tested, modular, and easy to maintain. This second edition of the bestselling Crafting Rails Applications has been updated to Rails 4 and discusses new topics such as streaming, mountable engines, and thread safety. Rails is one of the most extensible frameworks out there. This pioneering book deep-dives into the Rails plugin APIs and shows you, the intermediate Rails developer, how to use them to write better web applications and make your day-to-day work with Rails more productive. Rails Core developer Jose Valim guides you through eight different tutorials, each using test-driven development to build a new Rails plugin or application that solves common problems with these APIs. You'll learn how the Rails rendering stack works and customize it to read templates from the database while you discover how to mimic Active Record behavior, such as validations, in any other object. You'll find out how Rails integrates with Rack, the different ways to stream data from your web application, and how to mix Rails engines and Sinatra applications into your Rails apps, so you can choose the most appropriate tool for the job. In addition, you'll improve your productivity by customizing generators and responders. This book will help you understand Rails' inner workings, including generators, template handlers, internationalization, routing, and responders. With the knowledge you'll gain, you'll create well-tested, modular, and robust solutions for your next project.
Expert Practices for Everyday Rails Development
Author: Jose Valim
Publisher: Pragmatic Bookshelf
If you're an experienced Ruby programmer, Effective Ruby will help you harness Ruby's full power to write more robust, efficient, maintainable, and well-performing code. Drawing on nearly a decade of Ruby experience, Peter J. Jones brings together 48 Ruby best practices, expert tips, and shortcuts—all supported by realistic code examples. Jones offers practical advice for each major area of Ruby development, from modules to memory to metaprogramming. Throughout, he uncovers little-known idioms, quirks, pitfalls, and intricacies that powerfully impact code behavior and performance. Each item contains specific, actionable, clearly organized guidelines; careful advice; detailed technical arguments; and illuminating code examples. When multiple options exist, Jones shows you how to choose the one that will work best in your situation. Effective Ruby will help you systematically improve your code—not by blindly following rules, but by thoroughly understanding Ruby programming techniques. Key features of this concise guide include How to avoid pitfalls associated with Ruby's sometimes surprising idiosyncrasies What you should know about inheritance hierarchies to successfully use Rails (and other large frameworks) How to use misunderstood methods to do amazingly useful things with collections Better ways to use exceptions to improve code reliability Powerful metaprogramming approaches (and techniques to avoid) Practical, efficient testing solutions, including MiniTest Unit and Spec Testing How to reliably manage RubyGem dependencies How to make the most of Ruby's memory management and profiling tools How to improve code efficiency by understanding the Ruby interpreter's internals
48 Specific Ways to Write Better Ruby
Author: Peter J. Jones
Publisher: Pearson Education
A guide to building applications with Rails covers such topics as metaprogamming, Active Support library, advanced database functions, security principles, RESTful architecture, and optimizing performance.
Author: Brad Ediger
Publisher: "O'Reilly Media, Inc."
Speak directly to your system. With its simple commands, flags, and parameters, a well-formed command-line application is the quickest way to automate a backup, a build, or a deployment and simplify your life. With this book, you'll learn specific ways to write command-line applications that are easy to use, deploy, and maintain, using a set of clear best practices and the Ruby programming language. This book is designed to make any programmer or system administrator more productive in their job. Now updated for Ruby 2. Writing a command-line application that's self-documenting, robust, adaptable and forever useful is easier than you might think. Ruby is particularly suited to this task, because it combines high-level abstractions with "close to the metal" system interaction wrapped up in a concise, readable syntax. Plus, Ruby has the support of a rich ecosystem of open source tools and libraries. Ten insightful chapters each explain and demonstrate a command-line best practice. You'll see how to use these tools to elevate the lowliest automation script to a maintainable, polished application. You'll learn how to use free, open source parsers to create user-friendly command-line interfaces as well as command suites. You'll see how to use defaults to keep options simple for everyday users, while giving advanced users options for more complex tasks. There's no reason why a command-line application should lack documentation, whether it's part of a help command or a man page; you'll find out when and how to use both. Your journey from command-line novice to pro ends with a look at valuable approaches to testing your apps, and includes some fun techniques for outside-the-box, colorful interfaces that will delight your users. With Ruby, the command line is not dead. Long live the command line.
Control Your Computer, Simplify Your Life
Author: David Bryant Copeland
What others in the trenches say about The Pragmatic Programmer... “The cool thing about this book is that it’s great for keeping the programming process fresh. The book helps you to continue to grow and clearly comes from people who have been there.” —Kent Beck, author of Extreme Programming Explained: Embrace Change “I found this book to be a great mix of solid advice and wonderful analogies!” —Martin Fowler, author of Refactoring and UML Distilled “I would buy a copy, read it twice, then tell all my colleagues to run out and grab a copy. This is a book I would never loan because I would worry about it being lost.” —Kevin Ruland, Management Science, MSG-Logistics “The wisdom and practical experience of the authors is obvious. The topics presented are relevant and useful.... By far its greatest strength for me has been the outstanding analogies—tracer bullets, broken windows, and the fabulous helicopter-based explanation of the need for orthogonality, especially in a crisis situation. I have little doubt that this book will eventually become an excellent source of useful information for journeymen programmers and expert mentors alike.” —John Lakos, author of Large-Scale C++ Software Design “This is the sort of book I will buy a dozen copies of when it comes out so I can give it to my clients.” —Eric Vought, Software Engineer “Most modern books on software development fail to cover the basics of what makes a great software developer, instead spending their time on syntax or technology where in reality the greatest leverage possible for any software team is in having talented developers who really know their craft well. An excellent book.” —Pete McBreen, Independent Consultant “Since reading this book, I have implemented many of the practical suggestions and tips it contains. Across the board, they have saved my company time and money while helping me get my job done quicker! This should be a desktop reference for everyone who works with code for a living.” —Jared Richardson, Senior Software Developer, iRenaissance, Inc. “I would like to see this issued to every new employee at my company....” —Chris Cleeland, Senior Software Engineer, Object Computing, Inc. “If I’m putting together a project, it’s the authors of this book that I want. . . . And failing that I’d settle for people who’ve read their book.” —Ward Cunningham Straight from the programming trenches, The Pragmatic Programmer cuts through the increasing specialization and technicalities of modern software development to examine the core process--taking a requirement and producing working, maintainable code that delights its users. It covers topics ranging from personal responsibility and career development to architectural techniques for keeping your code flexible and easy to adapt and reuse. Read this book, and you'll learn how to Fight software rot; Avoid the trap of duplicating knowledge; Write flexible, dynamic, and adaptable code; Avoid programming by coincidence; Bullet-proof your code with contracts, assertions, and exceptions; Capture real requirements; Test ruthlessly and effectively; Delight your users; Build teams of pragmatic programmers; and Make your developments more precise with automation. Written as a series of self-contained sections and filled with entertaining anecdotes, thoughtful examples, and interesting analogies, The Pragmatic Programmer illustrates the best practices and major pitfalls of many different aspects of software development. Whether you're a new coder, an experienced programmer, or a manager responsible for software projects, use these lessons daily, and you'll quickly see improvements in personal productivity, accuracy, and job satisfaction. You'll learn skills and develop habits and attitudes that form the foundation for long-term success in your career. You'll become a Pragmatic Programmer.
From Journeyman to Master
Author: Andrew Hunt,David Thomas
Publisher: Addison-Wesley Professional
Text is everywhere. Web pages, databases, the contents of files--for almost any programming task you perform, you need to process text. Cut even the most complex text-based tasks down to size and learn how to master regular expressions, scrape information from Web pages, develop reusable utilities to process text in pipelines, and more. Most information in the world is in text format, and programmers often find themselves needing to make sense of the data hiding within. It might be to convert it from one format to another, or to find out information about the text as a whole, or to extract information fromit. But how do you do this efficiently, avoiding labor-intensive, manual work? Text Processing with Ruby takes a practical approach. You'll learn how to get text into your Ruby programs from the file system and from user input. You'll process delimited files such as CSVs, and write utilities that interact with other programs in text-processing pipelines. Decipher character encoding mysteries, and avoid the pain of jumbled characters and malformed output. You'll learn to use regular expressions to match, extract, and replace patterns in text. You'll write a parser and learn how to process Web pages to pull out information from even the messiest of HTML. Before long you'll be able to tackle even the most enormous and entangled text with ease, scything through gigabytes of data and effortlessly extracting the bits that matter. What You Need: This book requires a passing familiarity with the Ruby programming language, and assumes that you already have Ruby installed on your computer.
Extract Value from the Data That Surrounds You
Author: Rob Miller
Publisher: Pragmatic Bookshelf
The Complete Guide to Writing More Maintainable, Manageable, Pleasing, and Powerful Ruby Applications Ruby's widely admired ease of use has a downside: Too many Ruby and Rails applications have been created without concern for their long-term maintenance or evolution. The Web is awash in Ruby code that is now virtually impossible to change or extend. This text helps you solve that problem by using powerful real-world object-oriented design techniques, which it thoroughly explains using simple and practical Ruby examples. Sandi Metz has distilled a lifetime of conversations and presentations about object-oriented design into a set of Ruby-focused practices for crafting manageable, extensible, and pleasing code. She shows you how to build new applications that can survive success and repair existing applications that have become impossible to change. Each technique is illustrated with extended examples, all downloadable from the companion Web site,poodr.info. The first title to focus squarely on object-oriented Ruby application design, Practical Object-Oriented Design in Ruby will guide you to superior outcomes, whatever your previous Ruby experience. Novice Ruby programmers will find specific rules to live by; intermediate Ruby programmers will find valuable principles they can flexibly interpret and apply; and advanced Ruby programmers will find a common language they can use to lead development and guide their colleagues. This guide will help you Understand how object-oriented programming can help you craft Ruby code that is easier to maintain and upgrade Decide what belongs in a single Ruby class Avoid entangling objects that should be kept separate Define flexible interfaces among objects Reduce programming overhead costs with duck typing Successfully apply inheritance Build objects via composition Design cost-effective tests Solve common problems associated with poorly designed Ruby code
An Agile Primer
Author: Sandi Metz
Publisher: Pearson Education
You don't have to accept slow Ruby or Rails performance. In this comprehensive guide to Ruby optimization, you'll learn how to write faster Ruby code--but that's just the beginning. See exactly what makes Ruby and Rails code slow, and how to fix it. Alex Dymo will guide you through perils of memory and CPU optimization, profiling, measuring, performance testing, garbage collection, and tuning. You'll find that all those "hard" things aren't so difficult after all, and your code will run orders of magnitude faster. This is the first book ever that consolidates all the Ruby performance optimization advice in one place. It's your comprehensive guide to memory optimization, CPU optimization, garbage collector tuning, profiling, measurements, performance testing, and more. You'll go from performance rookie to expert. First, you'll learn the best practices for writing Ruby code that's easy not only on the CPU, but also on memory, and that doesn't trigger the dreaded garbage collector. You'll find out that garbage collection accounts for 80% of slowdowns, and often takes more than 50% of your program's execution time. And you'll discover the bottlenecks in Rails code and learn how selective attribute loading and preloading can mitigate the performance costs of ActiveRecord. As you advance to Ruby performance expert, you'll learn how profile your code, how to make sense out of profiler reports, and how to make optimization decisions based on them. You'll make sure slow code doesn't creep back into your Ruby application by writing performance tests, and you'll learn the right way to benchmark Ruby. And finally, you'll dive into the Ruby interpreter internals to really understand why garbage collection makes Ruby so slow, and how you can tune it up. What You Need: Some version of Ruby. The advice from this book applies to all modern Ruby versions from 1.9 to 2.2. 80% of the material will also be useful for legacy Ruby 1.8 users, and there is 1.8-specific advice as well.
Why Ruby is Slow, and How to Fix It
Author: Alexander Dymo
Publisher: Pragmatic Bookshelf
"Our tests are broken again!" "Why does the suite take so long to run?" "What value are we getting from these tests anyway?" Solve your testing problems by building and maintaining quality software with RSpec - the popular BDD-flavored Ruby testing framework. This definitive guide from RSpec's lead developer shows you how to use RSpec to drive more maintainable designs, specify and document expected behavior, and prevent regressions during refactoring. Build a project using RSpec to design, describe, and test the behavior of your code. Whether you're new to automated tests or have been using them for years, this book will help you write more effective tests. RSpec has been downloaded more than 100 million times and has inspired countless test frameworks in other languages. Use this influential Ruby testing framework to iteratively develop a project with the confidence that comes from well-tested code. This book guides you through creating a Ruby project with RSpec, and explores the individual components in detail. Start by learning the basics of installing and using RSpec. Then build a real-world JSON API, using RSpec throughout the process to drive a BDD-style outside-in workflow. Apply an effective test strategy to write fast, robust tests that support evolutionary design through refactoring. The rest of the book provides the definitive guide to RSpec's components. Use rspec-core's metadata to slice and dice your spec suite. Dig into rspec-expectations' matchers: compose them in flexible ways, specify expected outcomes with precision, and diagnose problems quickly with the help of good failure messages. Write fast, isolated tests with rspec-mocks' test doubles while pushing your code toward simpler interfaces. The authors, with a combined 20 years of automated testing experience, share testing wisdom that will lead to a fun, productive testing experience. What You Need: To follow along with the book, you'll need Ruby 2.2+. The book will guide you through installing RSpec 3 and setting up a new project to use it.
Build Ruby Apps with Confidence
Author: Myron Marston,Ian Dees
Publisher: Pragmatic Bookshelf
Contains fifty-eight Ruby scripts to solve a variety of problems for system administration, image manipulation, and management of a Website.
Useful Scripts that Solve Difficult Problems
Author: Steve Pugh
Publisher: No Starch Press
It’s easy to write correct Ruby code, but to gain the fluency needed to write great Ruby code, you must go beyond syntax and absorb the “Ruby way” of thinking and problem solving. In Eloquent Ruby, Russ Olsen helps you write Ruby like true Rubyists do–so you can leverage its immense, surprising power. Olsen draws on years of experience internalizing the Ruby culture and teaching Ruby to other programmers. He guides you to the “Ah Ha!” moments when it suddenly becomes clear why Ruby works the way it does, and how you can take advantage of this language’s elegance and expressiveness. Eloquent Ruby starts small, answering tactical questions focused on a single statement, method, test, or bug. You’ll learn how to write code that actually looks like Ruby (not Java or C#); why Ruby has so many control structures; how to use strings, expressions, and symbols; and what dynamic typing is really good for. Next, the book addresses bigger questions related to building methods and classes. You’ll discover why Ruby classes contain so many tiny methods, when to use operator overloading, and when to avoid it. Olsen explains how to write Ruby code that writes its own code–and why you’ll want to. He concludes with powerful project-level features and techniques ranging from gems to Domain Specific Languages. A part of the renowned Addison-Wesley Professional Ruby Series, Eloquent Ruby will help you “put on your Ruby-colored glasses” and get results that make you a true believer.
Author: Russ Olsen
Publisher: Addison-Wesley Professional
Summary: Ruby 1.9 was a major release of the language: it introduced multinationalization, new block syntax and scoping rules, a new, faster, virtual machine, and hundreds of new methods in dozens of new classes and modules. Ruby 2.0 is less radical--it has keyword arguments, a new regexp engine, and some library changes. This book describes it all. The first quarter of the book is a tutorial introduction that gets you up to speed with the Ruby language and the most important classes and libraries. Download and play with the hundreds of code samples as your experiment with the language. The second section looks at real-world Ruby, covering the Ruby environment, how to package, document, and distribute code, and how to work with encodings. The third part of the book is more advanced. In it, you'll find a full description of the language, an explanation of duck typing, and a detailed description of the Ruby object model and metaprogramming. The book ends with a reference section: comprehensive and detailed documentation of Ruby's libraries. You'll find descriptions and examples of more than 1,300 methods in 58 built-in classes and modules, along with brief descriptions of 97 standard libraries. Ruby makes your programming more productive; it makes coding fun again. And this book will get you up to speed with the very latest Ruby, quickly and enjoyably.
The Pragmatic Programmers' Guide
Author: David Thomas,Chad Fowler,Andrew Hunt
Today's modern Rails applications have lots of moving parts. Make sure your next production deployment goes smoothly with this hands-on book, which guides you through the entire production process. You'll set up scripts to install and configure all the software your servers need, including your application code. Once you're in production, you'll learn how to set up systems to monitor your application's health, gather metrics so you can stop problems before they start, and fix things when they go wrong. Deploying Rails takes you on a expertly guided tour of the current best practices in Rails deployment and management. You'll find in-depth explanations on effectively running a Rails app by leveraging popular open source tools such as Puppet, Capistrano, and Vagrant. Then you'll go beyond deployment and learn how to use Ganglia and Nagios to monitor your application's health and gather metrics so you can head off problems before they happen. You'll start out by building your own virtual environment by writing scripts to provision a production server with Vagrant and Puppet. Then you'll leverage the popular Rails deployment tool Capistrano to deploy an application into this infrastructure. Once the app is live, you'll monitor your application's health with Nagios, and configure Ganglia to collect system metrics. Finally, you'll see how to keep your data backed up, recover data when things go wrong, tame your log files, and use Puppet to automate everything along the way. Whether you're a Rails developer who wants a better understanding of the needs of a production Rails system, if you're a system administrator who wants to manage a Rails application, or if you're bridging the gap between development and operations, this book will be your roadmap to successful production deployment and maintenance, whether your application has ten users or ten million users. What You Need: The exercises and examples are most suited to a computer running some Unix variant, such as Mac OS X or Linux. But a Windows machine running Linux in a VirtualBox virtual machine is also sufficient. We'll show you how to set up a local virtual machine for your deployments; you won't need a dedicated server to hone your deployment skills. We expect you to have a basic familiarity with the Ruby programming language, the Ruby on Rails framework, and the Unix command line.
Automate, Deploy, Scale, Maintain, and Sleep at Night
Author: Anthony Burns,Tom Copeland
Based on the bestselling first edition, Beginning Ruby: From Novice to Professional, Second Edition is the leading guide for every type of reader who wants to learn Ruby from the ground up. The new edition of this book provides the same excellent introduction to Ruby as the first edition plus updates for the newest version of Ruby, including the addition of the Sinatra and Ramaze web application frameworks and a chapter on GUI development so developers can take advantage of these new trends. Beginning Ruby starts by explaining the principles behind object-oriented programming and within a few chapters builds toward creating a full Ruby application. By the end of the book, in addition to in-depth knowledge of Ruby, you'll also have basic understanding of many ancillary technologies such as SQL, XML, web frameworks, and networking. Introduces readers to the Ruby programming language Takes readers from basic programming skills to web development with topics like Ruby-based frameworks and GUI programming Covers many ancillary technologies in order to provide a broader picture (e.g., databases, XML, network daemons)
From Novice to Professional
Author: Peter Cooper
The Definitive Refactoring Guide, Fully Revamped for Ruby With refactoring, programmers can transform even the most chaotic software into well-designed systems that are far easier to evolve and maintain. What’s more, they can do it one step at a time, through a series of simple, proven steps. Now, there’s an authoritative and extensively updated version of Martin Fowler’s classic refactoring book that utilizes Ruby examples and idioms throughout–not code adapted from Java or any other environment. The authors introduce a detailed catalog of more than 70 proven Ruby refactorings, with specific guidance on when to apply each of them, step-by-step instructions for using them, and example code illustrating how they work. Many of the authors’ refactorings use powerful Ruby-specific features, and all code samples are available for download. Leveraging Fowler’s original concepts, the authors show how to perform refactoring in a controlled, efficient, incremental manner, so you methodically improve your code’s structure without introducing new bugs. Whatever your role in writing or maintaining Ruby code, this book will be an indispensable resource. This book will help you Understand the core principles of refactoring and the reasons for doing it Recognize “bad smells” in your Ruby code Rework bad designs into well-designed code, one step at a time Build tests to make sure your refactorings work properly Understand the challenges of refactoring and how they can be overcome Compose methods to package code properly Move features between objects to place responsibilities where they fit best Organize data to make it easier to work with Simplify conditional expressions and make more effective use of polymorphism Create interfaces that are easier to understand and use Generalize more effectively Perform larger refactorings that transform entire software systems and may take months or years Successfully refactor Ruby on Rails code
Author: Jay Fields,Shane Harvie,Martin Fowler,Kent Beck
Publisher: Pearson Education
Praise for Design Patterns in Ruby " Design Patterns in Ruby documents smart ways to resolve many problems that Ruby developers commonly encounter. Russ Olsen has done a great job of selecting classic patterns and augmenting these with newer patterns that have special relevance for Ruby. He clearly explains each idea, making a wealth of experience available to Ruby developers for their own daily work." —Steve Metsker, Managing Consultant with Dominion Digital, Inc. "This book provides a great demonstration of the key 'Gang of Four' design patterns without resorting to overly technical explanations. Written in a precise, yet almost informal style, this book covers enough ground that even those without prior exposure to design patterns will soon feel confident applying them using Ruby. Olsen has done a great job to make a book about a classically 'dry' subject into such an engaging and even occasionally humorous read." —Peter Cooper "This book renewed my interest in understanding patterns after a decade of good intentions. Russ picked the most useful patterns for Ruby and introduced them in a straightforward and logical manner, going beyond the GoF's patterns. This book has improved my use of Ruby, and encouraged me to blow off the dust covering the GoF book." —Mike Stok " Design Patterns in Ruby is a great way for programmers from statically typed objectoriented languages to learn how design patterns appear in a more dynamic, flexible language like Ruby." —Rob Sanheim, Ruby Ninja, Relevance Most design pattern books are based on C++ and Java. But Ruby is different—and the language's unique qualities make design patterns easier to implement and use. In this book, Russ Olsen demonstrates how to combine Ruby's power and elegance with patterns, and write more sophisticated, effective software with far fewer lines of code. After reviewing the history, concepts, and goals of design patterns, Olsen offers a quick tour of the Ruby language—enough to allow any experienced software developer to immediately utilize patterns with Ruby. The book especially calls attention to Ruby features that simplify the use of patterns, including dynamic typing, code closures, and "mixins" for easier code reuse. Fourteen of the classic "Gang of Four" patterns are considered from the Ruby point of view, explaining what problems each pattern solves, discussing whether traditional implementations make sense in the Ruby environment, and introducing Ruby-specific improvements. You'll discover opportunities to implement patterns in just one or two lines of code, instead of the endlessly repeated boilerplate that conventional languages often require. Design Patterns in Ruby also identifies innovative new patterns that have emerged from the Ruby community. These include ways to create custom objects with metaprogramming, as well as the ambitious Rails-based "Convention Over Configuration" pattern, designed to help integrate entire applications and frameworks. Engaging, practical, and accessible, Design Patterns in Ruby will help you build better software while making your Ruby programming experience more rewarding.
Author: Russ Olsen
Publisher: Pearson Education