Skip to content

Instantly share code, notes, and snippets.

Created March 12, 2016 16:43
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
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}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment