filemagic isn't the gem you're looking for. This appears to be someone's project not intended for public consumption (the rubygems page links to a company's website, and no source code is available).
Instead, install the ruby-filemagic gem. Here's the source and documentation. We can use the library like so:
begin
fm = FileMagic.new(FileMagic::MAGIC_MIME)
puts fm.file("foo.txt", true)
ensure
fm.close
end
...or by using the open() helper method, which automatically closes the resource for us:
FileMagic.open(FileMagic::MAGIC_MIME) { |fm| puts fm.file("foo.txt", true) }
This also works with yet another helper, mime(), which additionally sets the flag for us:
FileMagic.mime { |fm| puts fm.file("foo.txt", true) }
This gem relies on libmagic, a library used to identify file types using the file's magic number. The file command, commonly found on Unix/Linux systems, uses the same library:
$ file --mime-type foo.txt
foo.txt: text/plain
We can also invoke this command from the Ruby application to get a file's MIME type:
IO.popen(["file", "--mime-type", "--brief", "foo.txt"]) { |io| puts io.read.chomp }
MimeMagic is an alternative to FileMagic.