Ruby metaprogramming online tutorial [closed]
Asked Answered
E

6

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?

Ernestinaernestine answered 25/4, 2009 at 10:56 Comment(0)
A
24

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

Alyssa answered 25/4, 2009 at 12:46 Comment(6)
The Dwemthy's Array sample linked from there is a great (if not entirely practical) example of metaprogramming.Pluvial
This link seems to be broken :(Admission
This can now be found here: dannytatom.github.com/metaid Amazing.Thorsten
a quick intro alfreddd.com/2013/02/metaprogramming-in-ruby-in-nutshell.htmlInterosculate
And don't forget mislav.uniqpath.com/poignant-guide which is Why’s (Poignant) Guide to RubyGrigsby
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.)Rosemarierosemary
M
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 :)

Monogyny answered 27/4, 2009 at 3:27 Comment(1)
excellent PragProg screencast series indeed! pragprog.com/screencasts/v-dtrubyom/…Tummy
F
7

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

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

Fieldwork answered 16/1, 2012 at 11:46 Comment(0)
E
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

Eutrophic answered 11/2, 2011 at 21:35 Comment(3)
+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.Culmiferous
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/12582Culmiferous
Video of Metaprogramming Ruby (1.9) by Dave ThomasCulmiferous
B
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.

Bier answered 2/8, 2012 at 13:34 Comment(0)
E
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.

Elgon answered 13/7, 2013 at 9:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.