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]
# determine the type of file we have by looking for the #! line at the top
# careful–it might already be commented out!
my $commentString;
if ($fileString =~ m!^($perlCmt|$cCmt)?#\!\s*.*?/perl|^($perlCmt|$cCmt)?#\!\s*.*?/sh!) {
$commentString = $perlCmt;
} else {
$commentString = $cCmt;
}
[/perl]

…with this…

[perl]
my $fileName = “%%%{PBXFilePath}%%%”;

# determine the type of file we have by looking for the #! line at the top
# careful–it might already be commented out!
# Otherwise look at the file extension
my $commentString;
if ($fileString =~ m!^($perlCmt|$cCmt)?#\!\s*.*?/perl|^($perlCmt|$cCmt)?#\!\s*.*?/sh!
|| $fileName =~ m!\.(rb|pl|sh)$!) {
$commentString = $perlCmt;
} else {
$commentString = $cCmt;
}
[/perl]

Restart Xcode. Now commenting should work properly.

Comments are closed.