title: Extract a snippet of code from Ruby-based source file
body: <p>I've been playing with <a href="https://github.com/seattlerb/flog" rel="nofollow">flog</a> lately, its a pretty good
  tool to generate reports on code complexity for ruby applications. As a result of running
  <code>flog</code> on a project codebase you get an output that looks similar to this:</p>
  
  <pre><code>  1272.3: flog total
       7.3: flog/method average
  
      62.2: MyClass#foobar lib/myclass#foobar:123
      ... more similar lines ...
  </code></pre>
  
  <p>Example above provides a score for a method and references exact line number in the
  source code where that method is defined. This could be a regular instance/class
  method or any other "dynamic" method, eg. rake task and such.</p>
  
  <p>So the objective is to extract a snippet of code (most likely a method) from source
  file that starts with a line number defined in flog output. That snippet then could 
  be used in some web UI to show various code metrics (based on other tools like <code>flay</code>) 
  and/or stored in the database. As far as i can see, this task involves parsing ruby 
  code into AST, and then going through the tree to find corresponding start line and 
  figuring out end line number. I've done some experiments with this library - <a href="https://github.com/whitequark/parser" rel="nofollow">https://github.com/whitequark/parser</a>, works most of the time, but it's a bit tricky to
  get a correct result. </p>
  
  <p>Are there any other solutions to quickly extract a method code from a source file written
  in ruby?</p>