def make_subs(template) vars = Hash.new template.gsub(/\(\(.*?\)\)/) { |match| match.delete!("\(\)") pair = match.split(":") if vars.member?(pair[0]) new_subsitute = vars[pair[0]] else print pair.length > 1 ? "Enter a #{pair[1]}: " : "Enter a #{pair[0]}: " new_subsitute = gets vars[pair[0]] = new_subsitute if pair.length > 1 end match.replace(new_subsitute.chomp) } end #example #puts make_subs("We went to ((t:place)) to see ((Person)). ((t)) was so nice!")