Introducing the method_parser gem

require 'method_parser'

mp = MethodParser.new File.read('simple_number.rb')
mp.to_a

output:

[
  [:class, :SimpleNumber, 
    [
      [:def, :initialize, :private], 
      [:def, :add, :public], 
      [:def, :multiply, :public], 
      [:def, :divide, :private], 
      [:def, :square, :protected]
    ]
  ]
] 

update: 9:35pm 15th Sep 2014

Implemented to_xml

require 'method_parser'

mp = MethodParser.new File.read('simple_number.rb')
mp.to_xml

output:

<?xml version='1.0' encoding='UTF-8'?>
<doc>
  <klass name='SimpleNumber'>
    <def name='initialize' scope='private'></def>
    <def name='add' scope='public'></def>
    <def name='multiply' scope='public'></def>
    <def name='divide' scope='private'></def>
    <def name='square' scope='protected'></def>
  </klass>
</doc>

Resources

Tags:
Source:
2142hrs.txt
Published:
15-09-2014 21:42