Skip to Content
Effective Ruby: 48 Specific Ways to Write Better Ruby
book

Effective Ruby: 48 Specific Ways to Write Better Ruby

by Peter Jones
September 2014
Intermediate to advanced content levelIntermediate to advanced
240 pages
7h 2m
English
Addison-Wesley Professional
Content preview from Effective Ruby: 48 Specific Ways to Write Better Ruby

5. Metaprogramming

In Ruby, everything is open to modification at run time. Classes, modules, and even the behavior of individual objects can all be changed while a program is running. It’s trivial to write code that defines new classes or adds methods to an existing class or object. Virtually nothing is off limits. This so-called “metaprogramming” is one of Ruby’s most powerful features. It’s also one of its most dangerous.

There are a lot of good uses for metaprogramming. Cleaning up redundant code, generalizing a feature to work with more than one class, and creating domain-specific languages are just a few examples. But there are downsides, too. Methods like eval tend to become crutches, since they can be used to solve so many programming ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

The Ruby Way: Solutions and Techniques in Ruby Programming, Third Edition

The Ruby Way: Solutions and Techniques in Ruby Programming, Third Edition

Hal Fulton, André Arko
Ruby Cookbook, 2nd Edition

Ruby Cookbook, 2nd Edition

Lucas Carlson, Leonard Richardson

Publisher Resources

ISBN: 9780133847086Purchase book