<p>I understand that the <code>Ruby 1.8 AST</code> is traversed at runtime using a big switch statement, and many things like calling a method in a class or parent module involve the interpreter looking up and down the tree as it goes. Is there a straightforward way of accessing this <code>AST</code> in a <code>Ruby C</code> extension? Does it involve the Ruby extension API, or necessitate hacking the internal data structures directly?</p>

[{'answer_id': 13987, 'author': 'Orion Edwards', 'author_id': 234, 'author_profile': 'https://Stackoverflow.com/users/234', 'pm_score': 1, 'selected': False, 'text': '<p>A good starting point is probably to read the source of the <a href="http://rubyforge.org/projects/parsetree/" rel="nofollow noreferrer">ParseTree</a> library, which lets you get at and mess with the AST from ruby.</p>\n'}, {'answer_id': 14498, 'author': 'maetl', 'author_id': 14446, 'author_profile': 'https://Stackoverflow.com/users/14446', 'pm_score': 0, 'selected': False, 'text': "<p>Thanks for the tip. You're right - <code>ParseTree</code> seems to be the only code out there with any manipulation of the AST going on, except that it's actually written in RubyInline. </p>\n\n<p>So, it's a strange mixture between Ruby and C code. Very interesting reading, though.</p>\n\n<p>The other reference of course is eval.c from Ruby itself.</p>\n\n<p>It's going to take a fair bit of reading of both, to get my head around it.</p>\n"}]
['https://Stackoverflow.com/questions/13981', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/14446/']