[TxMt] Debugging Ruby commands

Allan Odgaard throw-away-1 at macromates.com
Fri Sep 29 10:03:16 UTC 2006


On 29/9/2006, at 11:44, Helge Hartmann wrote:

> I try to develop my own commands. So I'm new to Ruby, my commands  
> sometimes are buggy. How can I easily debug my commands. How do you  
> do it?

Depends of course on what they are doing, but for those which work on  
text, let it read from DATA instead of STDIN and put your sample  
input at the bottom of the script (after __END__) -- that way you can  
run it in TM and use the normal debug techniques.

Example:

     # quote input/selection
     text = DATA.read # change to STDIN.read when deploying
     puts text.gsub(/^/, '> ')

     __END__
     Lorem ipsum dolor sit amet, consectetur adipisicing
     elit, sed do eiusmod tempor incididunt ut labore et
     dolore magna aliqua. Ut enim ad minim veniam, quis
     nostrud exercitation ullamco laboris nisi ut
     aliquip ex ea commodo consequat. Duis aute irure
     dolor in reprehenderit in voluptate velit esse
     cillum dolore eu fugiat nulla pariatur. Excepteur
     sint occaecat cupidatat non proident, sunt in culpa
     qui officia deserunt mollit anim id est laborum.




More information about the textmate mailing list