Skip to content

Commit

Permalink
Ruby: Override 'class-name' definition (#2135)
Browse files Browse the repository at this point in the history
Unlike other C-like languages, in Ruby objects don't get initialized by
using `new Object` but `Object.new`. So whatever comes after `new`
probably isn't a classname.
  • Loading branch information
p8 authored and RunDevelopment committed Jan 5, 2020
1 parent 7f1c55b commit 401d4b0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
7 changes: 7 additions & 0 deletions components/prism-ruby.js
Expand Up @@ -13,6 +13,13 @@
greedy: true
}
],
'class-name': {
pattern: /(\b(?:class)\s+|\bcatch\s+\()[\w.\\]+/i,
lookbehind: true,
inside: {
'punctuation': /[.\\]/
}
},
'keyword': /\b(?:alias|and|BEGIN|begin|break|case|class|def|define_method|defined|do|each|else|elsif|END|end|ensure|extend|for|if|in|include|module|new|next|nil|not|or|prepend|protected|private|public|raise|redo|require|rescue|retry|return|self|super|then|throw|undef|unless|until|when|while|yield)\b/
});

Expand Down
2 changes: 1 addition & 1 deletion components/prism-ruby.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/languages/ruby/method_definition_feature.test
Expand Up @@ -32,7 +32,7 @@ end
"diameter",
["punctuation", ")"],
["keyword", "new"],
["class-name", ["diameter"]],
" diameter ",
["operator", "/"],
["number", "2"],
["keyword", "end"],
Expand Down

0 comments on commit 401d4b0

Please sign in to comment.