# Parsing Ruby to get info about method signatures?

**URL:** <https://www.ruby-forum.com/t/parsing-ruby-to-get-info-about-method-signatures/72927>\
**Category:** Ruby\
**Created:** [October 19, 2006, 11:17pm UTC](https://www.ruby-forum.com/t/parsing-ruby-to-get-info-about-method-signatures/72927 "2006-10-19T23:17:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lyle\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/45deac/32.png) [@Lyle\_J](https://www.ruby-forum.com/u/Lyle_J)\
**Post date:** [October 19, 2006, 11:17pm UTC](https://www.ruby-forum.com/t/parsing-ruby-to-get-info-about-method-signatures/72927/1 "2006-10-19T23:17:42Z")

</div>

I’m interested in parsing some Ruby code for the purpose of extracting  
information about the method signatures (including argument names and  
default argument values). For example, if I had a method like:

```
def foo(a, b=2, c=3)
  ...
end

```

I’d like to be able to programmatically determine that I have a method  
named “foo”, with arguments “a”, “b” and “c”, with defaults of 2 and 3  
for the latter two arguments. (I will use that information about the  
method signatures to generate some additional code.)

Does anyone have any experience with this? I looked at the XML  
generator for RDoc, but its output doesn’t appear to provide this kind  
of information. Ryan’s ParseTree library may do the trick, or worst  
case, I could write some kind of custom parsing tool myself. Just  
wanted to see if anyone has any thoughts on this.

---

<div class="post-metadata">

**Author:** ![Lyle\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/45deac/32.png) [@Lyle\_J](https://www.ruby-forum.com/u/Lyle_J)\
**Post date:** [October 20, 2006, 12:31am UTC](https://www.ruby-forum.com/t/parsing-ruby-to-get-info-about-method-signatures/72927/2 "2006-10-20T00:31:55Z")

</div>

On Fri, Oct 20, 2006 at 06:16:54AM +0900, Lyle J. wrote:

> for the latter two arguments. (I will use that information about the  
> method signatures to generate some additional code.)  
> […]

[http://eigenclass.org/hiki.rb?method+arguments+via+introspection](http://eigenclass.org/hiki.rb?method+arguments+via+introspection)

$ ruby method\_args.rb csv  
CSV::Cell#initialize (data = “”, is\_null = false)  
CSV::Cell#data ()  
CSV.open (path, mode, fs = nil, rs = nil)  
CSV.foreach (path, rs = nil)  
CSV.read (path, length = nil, offset = nil)  
CSV.readlines (path, rs = nil)  
CSV.generate (path, fs = nil, rs = nil)  
CSV.parse (str\_or\_readable, fs = nil, rs = nil)  
CSV.parse\_line (src, fs = nil, rs = nil)  
CSV.generate\_line (row, fs = nil, rs = nil)  
CSV.parse\_row (src, idx, out\_dev, fs = nil, rs = nil)  
CSV.generate\_row (src, cells, out\_dev, fs = nil, rs = nil)  
CSV::Reader.parse (str\_or\_readable, fs = “,”, rs = nil)  
CSV::Reader.create (str\_or\_readable, fs = “,”, rs = nil)  
CSV::Reader#each ()  
CSV::Reader#shift ()  
CSV::Reader#close ()  
CSV::Reader#initialize (dev)  
CSV::StringReader#initialize (string, fs = “,”, rs = nil)  
…

---

<div class="post-metadata">

**Author:** ![Lyle\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/45deac/32.png) [@Lyle\_J](https://www.ruby-forum.com/u/Lyle_J)\
**Post date:** [October 20, 2006, 7:26pm UTC](https://www.ruby-forum.com/t/parsing-ruby-to-get-info-about-method-signatures/72927/3 "2006-10-20T19:26:46Z")

</div>

On 10/19/06, Mauricio F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> [eigenclass.org](http://eigenclass.org/hiki.rb?method+arguments+via+introspection)

Thanks, Mauricio! I will check this out too.
