From: Doug Beaver Date: 2003-04-13T13:41:14+09:00 Subject: using ruby reflection to generate code hello, i'm curious if anyone out there is using ruby reflection to generate code for other languages. i love using ruby to prototype classes and their interactions, especially if i can't decide on a design and need to try a few different implementations. i'm writing lots of c++ and objective c these days, and it's much harder to turn around and quickly refactor class designs. has anyone tried using ruby's reflection to prototype classes in ruby and then render the class structure to other languages? i've started working along these lines so that i can call #render_objc on any object and get back two big strings, one for the header and one for the source. i use reflection to pull out instance variables and check their type, so a ruby array turns into a NSMutableArray *, hash to NSMutableDictionary *, etc, etc. i just look at variables, classes and methods with reflection, i don't parse the ruby code or try to do anything smart with it yet. the methods in the target language are just stubs. eventually, i would like to take the ruby code inside my methods and stick that as a comment inside the generated methods in my target language. then i can use ruby for RAD and generate stubs in my target language along with ruby code in comments so i can remember what each method was supposed to do. then i can move through the methods, porting the ruby code to my target language and getting a finished product more quickly. anyone else going down this road? perhaps you have some advice or pointers to examples you've found? i'm not sure it's going to work 100%, but i'm hoping it will allow me to save time. if anyone's interested, i can post code once i fix some bugs and clean it up. if i get something useful, i'm going to try this for c++ and perl as well. thanks, doug -- "Contrary to what most people say, the most dangerous animal in the world is not the lion or the tiger or even the elephant. It's a shark riding on an elephant's back, just trampling and eating everything they see." -- Jack Handey