Parsing Ruby to get info about method signatures?

Discussion in 'Ruby' started by Lyle Johnson, Oct 19, 2006.

  1. Lyle Johnson

    Lyle Johnson Guest

    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.
     
    Lyle Johnson, Oct 19, 2006
    #1
    1. Advertising

  2. On Fri, Oct 20, 2006 at 06:16:54AM +0900, Lyle Johnson wrote:
    > 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.)

    [...]

    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)
    ...

    --
    Mauricio Fernandez - http://eigenclass.org - singular Ruby
     
    Mauricio Fernandez, Oct 19, 2006
    #2
    1. Advertising

  3. Lyle Johnson

    Lyle Johnson Guest

    Lyle Johnson, Oct 20, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    358
    Chris Uppal
    Feb 19, 2004
  2. David S.
    Replies:
    0
    Views:
    251
    David S.
    May 30, 2005
  3. David Hilton

    searching for method signatures

    David Hilton, Sep 2, 2008, in forum: C Programming
    Replies:
    1
    Views:
    308
    Ben Bacarisse
    Sep 2, 2008
  4. david.karr
    Replies:
    4
    Views:
    403
    Joshua Cranmer
    Jun 16, 2009
  5. Chuck Insight
    Replies:
    0
    Views:
    164
    Chuck Insight
    Mar 11, 2005
Loading...

Share This Page