#!/usr/bin/ruby -w class MimeMap def initialize @map = Hash.new("*/*") File.open("/etc/mime.types").each{ |line| next if line =~ /^#|^\s*$/ type, extlist = line.chomp.split(/\t+/) if extlist ext = extlist.split(/ /) ext.each{ |i| @map[i] = type } end } end def typeof ext @map[ext] end def to_s s = "" @map.each_pair{ |k, v| s += "#{k}: #{v}\n" } s end end mm = MimeMap.new print mm.to_s while gets print "> #{mm.typeof($_.chomp!)}\n" end