Create a gist now

Instantly share code, notes, and snippets.

A script for searching a dictionary file for words that are relatable via a simple text substitution
# Inspired by a church billboard that read:
# "When I becomes we, illness becomes welness"
#
# usage:
# > ruby change-x-for-y.rb i we
# illness wellness
# inch wench
# it wet
# ...
a = ARGV.shift or "you must specify two words that are replaceable"
b = ARGV.shift or "you must specify TWO words that are replaceable"
a = a.downcase
b = b.downcase
words = File.readlines("/usr/share/dict/words").map { |w| w.strip.downcase }
dict = words.inject({}) { |h,k| h[k] = k.length; h }
words.each do |word|
next if word == a
word2 = word.gsub(/#{a}/, b)
if word2 != word && dict[word2]
puts "#{word} -> #{word2}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment