sawa sawa - 7 months ago 17
Ruby Question

Getting the list of available languages

How can I get the list of available languages (the short symbol to be passed when calling a method that represents the language) for CodeRay syntax highlighter?

I tried

require "coderay"
CodeRay::Scanners.constants


but that doesn't seem to give the information. (Even if I were able to get the constants that correspond to the languages, I still need another step to get the symbols that correspond to them.)




A related question is, I can do something like:

CodeRay::Scanners::Ruby # => CodeRay::Scanners::Ruby


but
CodeRay::Scanners.constants
doesn't include that. Why is that?

Answer

Method you are looking for is:

CodeRay::Scanners.list
#=> [:c, :clojure, :cpp, :css, :debug, :delphi, :diff, :erb, :go, :groovy,
#    :haml, :html, :java, :java_script, :json, :lua, :php, :python, :raydebug,
#    :ruby, :sass, :scanner, :sql, :taskpaper, :text, :xml, :yaml]
Comments