Vim and Emacs can detect the file type base on comments placed at the top of the file.
For emacs:
# -*- mode: ruby -*-
For vim:
# vi: set ft=ruby :
This is useful for vagrant configuration files which are written in Ruby but are named Vagrantfile for example.
Thank you for the feedback. bat (or rather syntect) can do the same, but it has to be specified in the respective syntax file. The C.sublime-syntax file, for example, has this header (see first_line_match):
name: C
file_extensions:
- c
- h
first_line_match: "-[*]-( Mode:)? C -[*]-"
scope: source.c
which bat correctly detects:

Unfortunately, only a few syntax definitions include this feature. The Ruby syntax includes this:
first_line_match: ^#!\s*/.*\bj?ruby\b
which means that it only detects shebangs:

However, note that Vagrantfile is correctly detected and displayed with Ruby syntax highlighting:

Actually, I guess correct highlighting of files such as Vagrantfile is only supported on master and not in the latest release. It has been integrated in syntect with my pull request here: https://github.com/trishume/syntect/pull/163.
Ah awesome! I'll wait for next release then. I'll look at syntect to ask if it's worth adding support for -*- mode: ruby -*-. Thanks for the answer!
I'll look at syntect to ask if it's worth adding support for -- mode: ruby --.
This would have to be done here: https://github.com/sublimehq/Packages
New release is out.
Just updated, and I can now see my Vagrantfiles with colors \o/
Thanks for this nice crate!
Thank you for the feedback!