in reply to Re: Extracting the Methods in a Ruby file
in thread Extracting the Methods in a Ruby file

This node falls below the community's minimum standard of quality and will not be displayed.

Replies are listed 'Best First'.
Re^3: Extracting the Methods in a Ruby file
by Corion (Patriarch) on Jan 07, 2011 at 09:12 UTC

    You will have to write a (very limited) parser for Ruby. If your Ruby code is vaguely well-formed, you can likely get by by remembering what items you saw in a list and removing the items whenever you encounter an end:

    my @stack; while (<RUBY_FILE>) { if (/^\s+def (.*)/) { push @stack, ['def',$1]; print; } elsif (/^\s+if (.*)/) { push @stack, ['if',$1]; print; } elsif (/^\s+end/) { my $block = pop @stack; if ($block->[0] eq 'def') { print "*** definition of $block->[1] ended\n"; }; } else { # collect, or do something else print; }; };

    But this is not a script writing service. You need to do your own work. You have not shown a single line of the code that you tried.