28

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?

0

6 Answers 6

24

The above article does refer to this but I'll post it for clarity: http://viewsourcecode.org/why/hacking/seeingMetaclassesClearly.html

Sign up to request clarification or add additional context in comments.

6 Comments

The Dwemthy's Array sample linked from there is a great (if not entirely practical) example of metaprogramming.
This link seems to be broken :(
This can now be found here: dannytatom.github.com/metaid Amazing.
Although this is the classic example of metaprogramming in Ruby, it is rather outdated. For one it uses _why's made up notation (metaclass, meta_def, meta_eval, etc.) rather than the more recent official terminology (singleton_class, define_singleton_method, etc.)
|
7

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 :)

1 Comment

excellent PragProg screencast series indeed! pragprog.com/screencasts/v-dtrubyom/…
7

This link explains various concepts(singleton,dynamic programming etc) of Ruby metaprogramming in a very systemetic manner.

http://ruby-metaprogramming.rubylearning.com/

Comments

6

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

3 Comments

+1 for "MetaProgramming Ruby". The book is basically a mentor exposing how these 'tricks'/'spells' are used. Apart from Ruby constructs related to metaprogramming it also shows how these features are USED in Rails to create all that "Rails-Magic"/conventions.
Metaprogramming Ruby Second Edition for Ruby 2.x is in beta April 2014. The Beta ebook is available here : pragprog.com/book/ppmetr2/metaprogramming-ruby See also : forums.pragprog.com/forums/288/topics/12582
2

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.

Comments

1

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:

  1. Blocks, Procs, & Lambdas
  2. Dynamic Classes & Methods
  3. Understanding Self
  4. 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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.