Test Highlights

Compared to other languages, Ruby does not have very good tool support for development. This might not be a problem for many of us: In the end, humans create the code, and not the tools.

Nevertheless, it would be great to have better tools. Or at least valid syntax highlighting!

The following table shows popular options for code highlighting, but none of them can manage to properly highlight more advanced Ruby features. Here is the:

Syntax Highlighter Comparison

Editor or Syntax Highlighter Version Highlights Ruby Correctly?¹
coderay 1.1.0 no. score: 4/5
ruby mine 7.1 RM-141.664 no. score: 4/5
rouge 1.8.0 no. score: 3/5
emacs 24.3.1 no. score: 2/5
pygments 1.6 no. score: 2/5
gedit 3.10.4 no. score: 1/5
prism.js 0.0.1 no. score: 1/5
rainbow.js 1.1.9 no. score: 1/5
src-highlight 3.1.6 (library: 4:0:0) no. score: 1/5
syntaxhighlighter.js 3.0.83 no. score: 1/5
vim 7.4.52 no. score: 1/5
atom 0.192.0 no. score: 0/5
highlight.js 8.5 no. score: 0/5
sublime text 3 Build 3083 no. score: 0/5

¹ Obviously, passing the test does not necessarily mean that a tool highlights Ruby correctly - but it is an indication.

The Idiosyncratic Ruby Syntax Highlight Test

# # #
# For Reference
42
"String with #{ :interpolation }"
/regex$/
$/

# # #
# TEST CASE 1: Question Marks
# SHOULD BE HIGHLIGHTED AS: Array of Strings - Operator - String - Operator - String

[?', ?(] ?'a':'b'

# # #
# TEST CASE 2: Percent Format
# SHOULD BE HIGHLIGHTED AS: String - Operator - Array of Numbers

"%d %d %d"%[1,2,3]

# # #
# TEST CASE 3: Space-delimited String
# SHOULD BE HIGHLIGHTED AS: String Delimiter - String

% 5 #

# # #
# TEST CASE 4: Multi-line Regex with Global Variable Interpolation
# SHOULD BE HIGHLIGHTED AS: Regex Delimiter - Regex -
#                           Interpolation Character (Optional) -
#                           Global Variable -
#                           Regex Delimiter - Regex Options

/
$$#$/
/omix

# # #
# TEST CASE 5: Nested Heredoc
# SHOULD BE HIGHLIGHTED AS: Method - String Delimiter - Operator -
#                           String Delimiter - String - String Delimiter
#                           String - String Delimiter

puts <<HERE<<<<THERE
foo 42
HERE
bla 43
THERE

More Idiosyncratic Ruby