From: gabriele renzi Date: 2004-11-23T02:53:04+09:00 Subject: Re: Typical/idiomatic examples of dynamic code generation with Ruby? Michael Neumann ha scritto: >> In the paper I'm comparing "idiomatic" examples of how these languages >> deal with common problems. Problem is, I'm quite new with Ruby and I'm >> a bit at a loss for examples on how to show Ruby's strengths with >> dynamic code generation (metaprogramming). That is often mentioned as >> one of Ruby's strengths. Don't get me wrong, I've found that Ruby has >> got the necesarry nuts and bolts but I couldn't really figure out what >> I could do with it, what I could not easily do with Python as well. >> >> So my question: do you know of any examples on the subject of dynamic >> code generation which would be typical for Ruby and could not be >> easily implemented in languages like Python? > I'm not sure samples in ruby would be hard in python and viceversa, but there are different idioms. Maybe ruby has some more runtime hooks like Class#inherited or Module#included. I /think/ that a good example could be the Interface pkg (java style check for interfaces) http://raa.ruby-lang.org/project/interface/ Toghether with the just named keyword-like class methods there is the class generation at runtime idiom, a built-in example is the Struct class, and a really nice one is Test::Unit::Mock, see a sample on this page: http://www.deveiate.org/code/Test-Unit-Mock/index.html Another thing is the usual relying on method_missing tricks, for wich I guess the best example is the Criteria library (wich happen to generate sql instead of ruby, so not really metaprogramming I think :) look at: http://mephle.org/Criteria/ It seem that your paper will be very interesting.. I even wonder how static languages handle this situations. just my 0.02 euro