I am doing a basic translator in Ruby (1.9.3). I pull out from the local test file ("a.txt") and using gsub to replace certain matches to simulate a translation from modern English to middle / early modern English. I ran into a reading problem:
How can I make reading a lot of gsub easier? I tried using multiple lines starting with
def translate @text.gsub(/my/, 'mine') @text.gsub(/\sis\s/, ' be ') end
but it only prints the final gsub. I can only assume that the second request overwrites the first. I would like to avoid creating a gsub giant query string and I cannot find a suitable answer.
Here is an example of my current program:
lines = File.readlines('a.txt') @text = lines.join def translate @text.gsub(/my/, 'mine').gsub(/\sis\s/, ' be ').gsub(/y\s/, 'ye ').gsub(/t\s/, 'te ').gsub(/t\,/, 'te,').gsub(/t\./, 'te.') end puts translate
I apologize in advance if this request seems solid. Hurrah!
source share