Commenting Ruby in Xcode

UPDATE: The new TextWrangler 2.2 has Ruby highlighting. Yay!

Coding Ruby in Xcode on a Mac? Like the built-in syntax highlighting but wondering why the apple+/ shortcut makes C comments, not Ruby comments? The following might save you a few minutes digging.

Find and open this file:

/Library
  /Application Support
    /Apple
      /Developer Tools
        /Scripts
          /10-User Scripts
            /30-Comments
              /10-un_commentLines.pl

Replace this...

PERL:
  1. # determine the type of file we have by looking for the #! line at the top
  2. # careful--it might already be commented out!
  3. my $commentString;
  4. if ($fileString =~ m!^($perlCmt|$cCmt)?#\!\s*.*?/perl|^($perlCmt|$cCmt)?#\!\s*.*?/sh!) {
  5.     $commentString = $perlCmt;
  6. } else {
  7.     $commentString = $cCmt;
  8. }

...with this...

PERL:
  1. my $fileName = "%%%{PBXFilePath}%%%";
  2.  
  3. # determine the type of file we have by looking for the #! line at the top
  4. # careful--it might already be commented out!
  5. # Otherwise look at the file extension
  6. my $commentString;
  7. if ($fileString =~ m!^($perlCmt|$cCmt)?#\!\s*.*?/perl|^($perlCmt|$cCmt)?#\!\s*.*?/sh!
  8. ||  $fileName =~ m!\.(rb|pl|sh)$!) {
  9.     $commentString = $perlCmt;
  10. } else {
  11.     $commentString = $cCmt;
  12. }

Restart Xcode. Now commenting should work properly.

Leave a Reply