By Paolo Perrotta
Everyone within the Ruby international looks conversing approximately metaprogramming--how you should use it to take away duplication on your code and write stylish, appealing courses. you can now get in at the motion as well.
This e-book describes metaprogramming as an integral part of Ruby. when you comprehend the rules of Ruby, together with the thing version, scopes, and eigenclasses, you are in your approach to utilising metaprogramming either on your day-by-day paintings and on your enjoyable, after-hours projects.
studying metaprogramming does not must be tricky or dull. via taking you on a Monday-through-Friday workweek experience with a couple of programmers, Paolo Perrotta is helping make gaining knowledge of the artwork of metaprogramming either effortless and entertaining.
The booklet is packed with:
Pragmatic examples of metaprogramming in motion, lots of which come immediately from well known libraries or frameworks, reminiscent of Rails. Programming demanding situations that allow you to test and play with probably the most enjoyable, "out-there" metaprogramming suggestions. Metaprogramming spells--34 sensible recipes and idioms that you should examine and practice instantaneously, to jot down code that's guaranteed to impress.
no matter if you are a Ruby apprentice at the route to studying the language or a Ruby wiz looking for new assistance, this e-book is for you.
Read or Download Metaprogramming Ruby: Program Like the Ruby Pros PDF
Best Programming books
Physics is basically vital to video game programmers who want to know easy methods to upload actual realism to their video games. they should consider the legislation of physics when growing a simulation or online game engine, really in 3D special effects, for the aim of constructing the consequences seem extra actual to the observer or participant.
C the way to software, 6e, is perfect for introductory classes in C Programming. additionally for classes in Programming for Engineers, Programming for company, and Programming for know-how. this article presents a necessary reference for programmers and somebody drawn to studying the c program languageperiod.
Not anything lower than a revolution within the means internet purposes are constructed,Ruby on Rails (RoR) boasts a simple and intuitive nature that avoids programming repetition and makes it infinitely more straightforward to construct for the net. This e-book captures the present most sensible practices to teach you the best option to construct a incredible internet software with RoR.
Many programmers code via intuition, hoping on handy conduct or a "style" they picked up early on. they don't seem to be aware of the entire offerings they make, like how they structure their resource, the names they use for variables, or the categories of loops they use. they are targeted solely on difficulties they are fixing, strategies they are growing, and algorithms they're enforcing.
Additional resources for Metaprogramming Ruby: Program Like the Ruby Pros
For those who locate this idea magnificent, keep in mind that in a dynamic language resembling Ruby each item has its personal checklist of example variables, self reliant of alternative objects—even different gadgets of a similar type. 1. five What occurs if you happen to name a style? the place you study humble process name calls for loads of paintings on Ruby’s half and also you make clear a twisted piece of code. After a few hours engaged on Bookworm, you and invoice already think convinced sufficient to mend a few minor insects the following and there—but now, as your operating day is drawing to an in depth, you end up caught. trying to repair a long-standing trojan horse, you’ve stumbled upon a tangle of periods, modules, and strategies that you simply can’t make head or tail of. forty six W HAT H APPENS W chicken Y OU C ALL A M ETHOD ? determine 1. five: Bill’s diagram, greater through you “Stop! ” invoice shouts, startling you. “This code is simply too advanced! to appreciate it, you'll want to research intimately what occurs if you name a mode. ” And ahead of you could react, he dives into one more lecture. for those who name a style, invoice explains, Ruby does issues: 1. It unearths the tactic. this can be a method referred to as approach search for. 2. It executes the tactic. to do this, Ruby wishes whatever known as self. This process—find a mode after which execute it—happens in each object-oriented language. In a really dynamic language like Ruby, even if, it’s fairly vital that you just comprehend the method extensive. have you discovered your self thinking about the place a selected process used to be outlined? in case you have, then you definitely may still certainly understand extra approximately technique look up and self. invoice goes to provide an explanation for strategy look up first, and he’ll come round to self later. forty seven W HAT H APPENS W chicken Y OU C ALL A M ETHOD ? technique search for concerning the least difficult case of process look up. glance again at determine 1. 1, on web page 36. for those who name a mode, Ruby appears to be like into the object’s type and unearths the tactic there. ahead of you examine a extra advanced instance, notwithstanding, you want to find out about new options: the receiver and the ancestors chain. The receiver is just the item that you just name a mode on. for instance, when you write my_string. reverse(), then my_string is the receiver. to appreciate the concept that of an ancestors chain, simply examine any Ruby type. Then think relocating from the category into its superclass, then into the superclass’s superclass, and so forth, till you achieve item (the default superclass) after which, eventually, BasicObject (the root of the Ruby category hierarchy). the trail of periods you simply traversed is the ancestors chain of the category. (The ancestors chain additionally comprises modules, yet ignore them for now. invoice gets round to modules in a piece. ) Now that you simply recognize what a receiver is and what an ancestors chain is, you could sum up the method of approach look up in one sentence: to discover a style, Ruby is going within the receiver’s category, and from there it climbs the ancestors chain until eventually it unearths the tactic. invoice grabs the keyboard and writes an instance: obtain object_model/lookup. rb classification MyClass def my_method; 'my_method()' ; finish finish type MySubclass < MyClass finish obj = MySubclass.