Found in 3 comments on Hacker News
vinceguidry · 2014-10-01 · Original thread
For any struggling to understand Ruby's metaprogramming, the rather short and succinct Metaprogramming Ruby is an excellent read. There's a method to the madness of define_method, method_missing, the various eval methods, the difference between Blocks, Procs, and Lambdas. Most of it revolves around manipulating scopes.

It also shows how you can iterate from the ugliest, most powerful, most dangerous eval method by pulling out the functionality you need into less-powerful, safer manipulations. It's all Ruby code until it's actually executed, so it can all be manipulated at runtime.

http://www.amazon.com/Metaprogramming-Ruby-Program-Like-Pros...

happy4crazy · 2011-04-22 · Original thread
Metaprogramming Ruby [0] explains Ruby's handling of scope really well.

Also, you might enjoy a silly gem I wrote a while ago called ghost_attributes [1]. It uses closures to mimic attr_accessor. The funny thing about it is that your ghost attributes are completely inaccessible from outside the object, unlike normal instance variables, which are always reachable via things like instance_variable_get. Fun/weird stuff :)

[0] http://www.amazon.com/Metaprogramming-Ruby-Program-Like-Pros...

[1] https://github.com/happy4crazy/ghost_attributes

nolite · 2010-08-14 · Original thread
Ruby is waay more than just a "slightly different syntax and grammar", and you can't really understand what's happening behind the scenes in rails until you understand the tools at work.

If you've got the basics of Ruby down, get this book and take it to the next level

http://www.amazon.com/Metaprogramming-Ruby-Program-Like-Pros...

As for the gems in rails..study their code, learn what they try to do, then program it yourself, else you might spend forever fighting with poorly documented and fragile gems, that were never really intended for long term production use anyway..

just my 2 cents..

Fresh book recommendations delivered straight to your inbox every Thursday.