6

Possible Duplicate:
How to extract the code from a Proc object?

What is the best way to turn a proc or method object into its source string? So far, I have tried two approaches. One is to achieve the source location of the proc and read that part of the source code. The other is to use the libraries sorcerer, and ripper. I am not sure what was the correct way to do it. What is the best may depend on various factors: robustness, faithfulness to the original, speed, etc. Including the approaches that I suggested, but not limited to them, please suggest a strategy, and evaluate its limitations.

Community
  • 1
  • 1
sawa
  • 165,429
  • 45
  • 277
  • 381
  • 3
    Related questions: http://stackoverflow.com/questions/4811501/how-to-extract-the-code-from-a-proc-object http://stackoverflow.com/questions/2082741/ruby-block-to-string-instead-of-executing http://stackoverflow.com/questions/4404362/compare-the-content-not-the-results-of-procs – Andrew Grimm Apr 20 '11 at 23:15
  • @Andrew Thanks for the link. sourcify seems to work for me. – sawa Apr 21 '11 at 00:45
  • Since Andrew noticed me some useful links, and now that I know it is a duplicate, I am going to vote myself to close this as duplicate. Please feel free to do so. – sawa Apr 21 '11 at 00:58

0 Answers0