From: Peter Zotov Date: 2011-02-10T22:15:31+09:00 Subject: Re: Modifying the AST of a running Ruby script in-place On Thu, 10 Feb 2011 21:01:31 +0900 John Feminella wrote: > Is there a way to not merely _construct_ the AST of a Ruby script, but > also to _modify_ it in-memory, thus producing a different script? (I > realize that there's no Ruby spec and thus, every Ruby implementation > is going to have a different parse tree and thus a different answer. > My question is confined mostly to MRI.) The problem is, there is no more AST in runtime in MRI 1.9. This was the biggest 1.9 change: in 1.8 Ruby has traversed and executed the AST directly, and that was painfully slow. 1.9 now uses bytecode instead; you can take a look at RubyVM::InstructionSequence. -- WBR, Peter Zotov