master
1#!/usr/bin/env ruby
2
3# Our test cases will always use the same dictionary file (with SHA1
4# 6b898d7c48630be05b72b3ae07c5be6617f90d8e). Running `test/harness`
5# will automatically download this dictionary for you if you don't
6# have it already.
7
8class Array
9 def faster_include?(n)
10 !(self & [n]).empty?
11 end
12end
13
14path = ARGV.length > 0 ? ARGV[0] : '/usr/share/dict/words'
15entries = File.read(path).split("\n")
16
17contents = $stdin.read
18output = contents.gsub(/[^ \n]+/) do |word|
19 if entries.faster_include?(word.downcase)
20 word
21 else
22 "<#{word}>"
23 end
24end
25print output