こどもてるびぃ

 | 

2006-05-26

[]1問目

Quiz1: Mad Libs - bongoleのRubyを楽しむ日記 - Rubyist

words = []
vars = {}
while word = ARGV.shift
  if var = vars[word]
    words.push(var)
  elsif word.match(/^([^:]+):(.*)$/)
    words.push($2)
    vars[$1] = $2
  else
    words.push(word)
  end
end
while line = gets
  puts line.gsub(/\(\([^)]*\)\)/) { words.shift }
end

ふつー。もう少し考える。

 |