From: John Feminella Date: 2011-02-18T23:54:41+09:00 Subject: Re: Ruby reflection - get method definition as a string I haven't looked at James's gem, but if live_ast can map AST structures to lines in the source, then it'd be easy to determine which range of lines in a file is the interesting part. Then you'd know precisely what section to grab. ~ jf -- John Feminella Principal Consultant, BitsBuilder LI: http://www.linkedin.com/in/johnxf SO: http://stackoverflow.com/users/75170/ On Fri, Feb 18, 2011 at 09:30, James M. Lawrence wrote: > Adam Lauper wrote in post #982302: >> Hi Folks - I am running some ruby tests and would like to print out >> the actual test to the console or store it to a file.  The tests are >> written as classes with a setup, run, and teardown method. >> So here's my question: is there a way to get the class definition or >> method definitions as a "string", so that I can print it out (to a >> file or console)? >> I know ruby supports a lot of reflection (like .methods >> or .constants), but I'm not seeing how to do this. >> Thanks! > > I just released a gem which gives access to the source code of methods > and procs (http://github.com/quix/live_ast). See the "to_ruby" section > of the readme. Since the string returned by to_ruby is a parsed/unparsed > version of your code, it probably won't match the original source (and > comments will be gone), but it may suffice for your needs. > > -- > Posted via http://www.ruby-forum.com/. > >