The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Using introspection to get method arguments and other info

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Eigen Class

Posts: 358
Nickname: eigenclass
Registered: Oct, 2005

Eigenclass is a hardcore Ruby blog.
Using introspection to get method arguments and other info Posted: Sep 8, 2006 8:27 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Eigen Class.
Original Post: Using introspection to get method arguments and other info
Feed Title: Eigenclass
Feed URL: http://feeds.feedburner.com/eigenclass
Feed Description: Ruby stuff --- trying to stay away from triviality.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Eigen Class
Latest Posts From Eigenclass

Advertisement

I just wrote a small script that uses introspection to tell you the methods defined in a file plus their argument names and default values. It's a quick hack, but it works surprisingly well.

Here are some examples:

   $ ruby -rmethod_args -rcsv -e1
   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)
   [...]

method_args.rb can detect arguments with default values and "splat args":

   $ ruby -rmethod_args -rbenchmark -e1
   Benchmark#benchmark (caption = "", label_width = nil, fmtstr = nil, *labels)
   Benchmark#bm (label_width = 0, *labels)
   Benchmark#bmbm (width = 0)
   Benchmark#measure (label = "")
   [...]

The nice thing is that method_args.rb actually requires your library code and will take into account its dependencies too. So it'll tell you all the methods you'd pull into your runtime if you required some file.

At the time being, all this script does is writing the methods it found on stdout, but it could for instance send them to another application through a socket to provide fairly accurate intellisense information, or generate rich tags, or...


Read more...

Read: Using introspection to get method arguments and other info

Topic: JRuby guys hired by Sun, Netbeans Ruby IDE to come? Previous Topic   Next Topic Topic: What's New in Edge Rails: An Explicit Locals Hash

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use