# How to invoke RubyParser on a class?

**URL:** <https://www.ruby-forum.com/t/how-to-invoke-rubyparser-on-a-class/171830>\
**Category:** Ruby\
**Created:** [July 9, 2009, 9:08pm UTC](https://www.ruby-forum.com/t/how-to-invoke-rubyparser-on-a-class/171830 "2009-07-09T21:08:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Juston\_Davies](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e68b1a/32.png) [@Juston\_Davies](https://www.ruby-forum.com/u/Juston_Davies)\
**Post date:** [July 9, 2009, 9:08pm UTC](https://www.ruby-forum.com/t/how-to-invoke-rubyparser-on-a-class/171830/1 "2009-07-09T21:08:11Z")

</div>

I think I’ve got the basic concept and I got the test case to  
work where you can parse “1+1” and then use Ruby2Ruby to get it back  
to “1+1.” But how do I get RubyParser to parse a class. I tried  
handing it method, proc and lambda objects as well as the class  
outright and it always throws an error. What do I need to give  
RubyParser to get it to parse a defined class or class::method?

```
 After two days of searching every lead I could find and reading

```

the code I’m at wits end, maybe I’m missing something really obvious.  
I’d really appreciate any advice I could get.

---

<div class="post-metadata">

**Author:** ![Juston\_Davies](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e68b1a/32.png) [@Juston\_Davies](https://www.ruby-forum.com/u/Juston_Davies)\
**Post date:** [July 10, 2009, 6:15am UTC](https://www.ruby-forum.com/t/how-to-invoke-rubyparser-on-a-class/171830/2 "2009-07-10T06:15:57Z")

</div>

> What do I need to give  
> RubyParser to get it to parse a defined class or class::method?

With ParseTree there is a method to do this. With RubyParser I don’t  
think there is. With 1.9.1 you could use {method, proc}#source\_location  
to try to re-locate the source and parse it from there.

---

<div class="post-metadata">

**Author:** ![Juston\_Davies](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e68b1a/32.png) [@Juston\_Davies](https://www.ruby-forum.com/u/Juston_Davies)\
**Post date:** [July 10, 2009, 9:35am UTC](https://www.ruby-forum.com/t/how-to-invoke-rubyparser-on-a-class/171830/3 "2009-07-10T09:35:56Z")

</div>

Excellent, I’ll look into it! Im still in 1.8.6 now but I’m Im working  
my way to 1.9.+  
Thanks a for the reply, this gives me some much needed direction.
