I have just started to learn Ruby and got a good take on the basics. I keep hearing that one of the cool things that Ruby does very well is metaprogramming, but none of the tutorials I've read cover this. Searching Google I can only seem to find paid for ruby metaprogramming screen casts.
So, where can I find a good Ruby metaprogramming tutorial online?
The above article does refer to this but I'll post it for clarity:
http://viewsourcecode.org/why/hacking/seeingMetaclassesClearly.html
If you are prepared to outlay a little cash, then The Pragmatic Programmers website has an excellent screencast series on the Ruby Object Model and metaprogramming. It's not very expensive and is a very comprehensive series that goes over a lot of cool stuff and worth every cent.
I need to watch it again to try and get my head around some of the concepts, then I can be one of the cool meta crowd :)
This link explains various concepts(singleton,dynamic programming etc) of Ruby metaprogramming in a very systemetic manner.
http://ruby-metaprogramming.rubylearning.com/
These 2 books should get you going...
"The Ruby Programming Language" by Matz and Flanagan.
"Metaprogramming Ruby: Program Like the Ruby Pros" by Paolo Perrota
Here is a good introduction for ruby metaprogramming: http://practicalruby.blogspot.com/2007/02/ruby-metaprogramming-introduction.html
- http://rubylearning.com/blog/2010/11/23/dont-know-metaprogramming-in-ruby/
- http://ruby-metaprogramming.rubylearning.com/
- http://yehudakatz.com/2009/11/15/metaprogramming-in-ruby-its-all-about-the-self/
- http://rubyrogues.com/metaprogramming-in-ruby/
- http://pragprog.com/screencasts/v-dtrubyom/the-ruby-object-model-and-metaprogramming
- https://github.com/ashbb/ruby_metaprogramming_study_note
These should get you started.
and more
- http://www.vanderburg.org/Speaking/Stuff/oscon05.pdf
- http://99designs.com/tech-blog/blog/2012/10/30/abusing-ruby-for-fun-and-profit/
- http://www.amazon.com/Design-Patterns-Ruby-Russ-Olsen/dp/0321490452
- http://www.apress.com/9781447141259
Here is a nice overview: http://ola-bini.blogspot.com/2006/09/ruby-metaprogramming-techniques.html
You can take a look at http://rubymonk.com/learning/books/2-metaprogramming-in-ruby - it's the second free book on programming in Ruby that we've release on RubyMonk.com.
I'm surprised no one has mentioned Code School. Their "Ruby Bits Part 2" course follows material similar to the second half of the excellent book "Eloquent Ruby.", with a nice set of interactive tests to help drill the material into you.
Link: http://www.codeschool.com/courses/ruby-bits-part-2
Levels:
- Blocks, Procs, & Lambdas
- Dynamic Classes & Methods
- Understanding Self
- Missing Methods
5 & 6. DSLs
It does cost $20 a month for a subscription (for which you also get access to all of their other courses), but for me it was totally worth it.