Skip to content

Instantly share code, notes, and snippets.

@jwarchol
Created October 27, 2008 23:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwarchol/20235 to your computer and use it in GitHub Desktop.
Save jwarchol/20235 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
def main(args)
memory = {}
post_sub_regexp = /\(\([^)]+\)\)/
input = IO.read(args[0])
while matches = input.match(/\(\(([^)]+)\)\)/) do
if matches[1] =~ /:/
var, prompt = matches[1].split(":")
elsif memory[matches[1]]
input.sub!(post_sub_regexp, memory[matches[1]])
next
else
var = nil
prompt = matches[1]
end
print "Please provide #{prompt} : "
resp = STDIN.gets.chomp
if var
memory[var] = resp
end
input.sub!(post_sub_regexp, resp)
end
print "\n"
puts input
end
if __FILE__ == $PROGRAM_NAME
main ARGV
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment