# Node hierarchies, and the inspection thereof

**URL:** <https://www.ruby-forum.com/t/node-hierarchies-and-the-inspection-thereof/193935>\
**Category:** Ruby\
**Created:** [August 26, 2010, 7:52pm UTC](https://www.ruby-forum.com/t/node-hierarchies-and-the-inspection-thereof/193935 "2010-08-26T19:52:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![xazoola](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/c4cdca/32.png) [@xazoola](https://www.ruby-forum.com/u/xazoola)\
**Post date:** [August 26, 2010, 7:52pm UTC](https://www.ruby-forum.com/t/node-hierarchies-and-the-inspection-thereof/193935/1 "2010-08-26T19:52:11Z")

</div>

Sorry if this belongs in Ruby Core, though I don’t really think it does  
since it’s more about writing gems than it is Ruby itself.

I’ve been looking (on and off) for the past several months for a way to  
accomplish this topic’s namesake. There are many gems for Ruby 1.8x and  
a few that even support earlier previews of 1.9.1, but I haven’t found  
any that support the current version (1.9.2) or even the official 1.9.1  
release.

For reference, a few of the better-known examples of what I’m looking  
for are:

ParseTree - [http://rubyforge.org/projects/parsetree/](http://rubyforge.org/projects/parsetree/)  
RubyNode - [http://rubynode.rubyforge.org/api.html](http://rubynode.rubyforge.org/api.html)

I understand that at some point, ‘node.h’ was removed from the public  
API. This is one of the reasons that most of these gems don’t support  
the current release. So I guess my questions are…

1. Are there ANY gems out there that have found a way to inspect the  
node hierarchy in 1.9 that I might have missed?

2. The ruby-debug19 gem seems to get around the missing header files by  
relying on the ruby\_core\_source gem. I didn’t look at it in much detail,  
but that gem seems to pull in the missing headers directly. That said,  
if one were to take this approach, would it be feasible at all to  
implement the functionality I’m looking for? Or is something missing at  
a much more fundamental level? I’ve tried to hack a proof of concept  
together (several times) and they seem to _almost_ work, but invariably  
seem to end with a segfault. Even the “rb\_parser\_dump\_tree” function in  
the Ruby19 node.c gives me a segfault, though it does make it plainly  
obvious that it was never meant for public consumption.

3. Is there any resource, in addition to reading the Ruby source code  
itself, that might document the various macros in node.h? I’ve been able  
to figure some of them out but others have me downright stumped. I  
suspect my lack of understanding these macros may be related to the  
inevitable segfaulting of my code (though that still doesn’t explain the  
rb\_parser\_dump\_tree segfaults).

4. Is this really a big deal? I have some really interesting ideas for  
gems that I’d dearly like to implement, but I’m afraid to bother with  
them because relying on RubyNode or ParseTree would make my work totally  
incompatible with Ruby 1.9. Are people actually using 1.9 in the field  
yet? For example, while Rails 3 does support 1.9.2 officially, is anyone  
actually planning to use it with 1.9 or will the user base be sticking  
with 1.8.7 for the foreseeable future (hopefully long enough for the  
missing node stuff to be added back into 1.9)?

Sorry for the novel. I guess I’m just at a point where I don’t know  
whether to shrug off this issue and stick with 1.8; implement it myself;  
wait for someone else (or a new version of Ruby); or drop my ideas  
altogether (which would be truly disappointing, but is unavoidable if  
node inspection is gone forever).

Thanks for the help,  
Colin MacKenzie IV

---

<div class="post-metadata">

**Author:** ![xazoola](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/c4cdca/32.png) [@xazoola](https://www.ruby-forum.com/u/xazoola)\
**Post date:** [August 26, 2010, 8:35pm UTC](https://www.ruby-forum.com/t/node-hierarchies-and-the-inspection-thereof/193935/2 "2010-08-26T20:35:01Z")

</div>

> I’ve been looking (on and off) for the past several months for a way to  
> accomplish this topic’s namesake. There are many gems for Ruby 1.8x and  
> a few that even support earlier previews of 1.9.1, but I haven’t found  
> any that support the current version (1.9.2) or even the official 1.9.1  
> release.

Currently there’s no way to get the nodes of methods with 1.9.{1,2}  
It might be added in 1.9.3  
You can get to the code by using Method#source\_location at times, then  
re-parse.  
GL!  
-r

---

<div class="post-metadata">

**Author:** ![xazoola](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/c4cdca/32.png) [@xazoola](https://www.ruby-forum.com/u/xazoola)\
**Post date:** [August 27, 2010, 2:11pm UTC](https://www.ruby-forum.com/t/node-hierarchies-and-the-inspection-thereof/193935/3 "2010-08-27T14:11:38Z")

</div>

Roger P. wrote:

> > I’ve been looking (on and off) for the past several months for a way to  
> > accomplish this topic’s namesake. There are many gems for Ruby 1.8x and  
> > a few that even support earlier previews of 1.9.1, but I haven’t found  
> > any that support the current version (1.9.2) or even the official 1.9.1  
> > release.
> 
> Currently there’s no way to get the nodes of methods with 1.9.{1,2}  
> It might be added in 1.9.3  
> You can get to the code by using Method#source\_location at times, then  
> re-parse.  
> GL!  
> -r

That’s what I suspected, but was hoping I’d just missed something. ☹

Any idea what the actual likelihood is of this finding its way into  
1.9.3? As mentioned, I’d hate to write code that can’t be brought in  
line with the latest release.

Thanks for the help, and also for pointing out Method#source\_location.  
Maybe I can use RubyNode or some such for 1.8, and fall back to  
#source\_location in 1.9.x. Not ideal, but better than nothing!

-cm4
