From: Harry Kakueki Date: 2011-09-15T00:23:20+09:00 Subject: Re: Tough Ruby Homework > I'm trying to take a long piece of text, find a word, and get that word > and the 3 words on either side of it and put that new "string" into > another variable. > I don't know what work homework means. But, I learn something from these things and maybe someone else will, too. So, here is a step towards the first part. If it is wrong, you can fix it. str = "If Robert likes green beans, girls with mustaches, and teddy bears, John thinks Robert is strange." f,g = str.split(/\s+/), "Robert" p (0...f.size).select{|x| f[x]==g}.map{|y| (y-[3,y].min..y+3)}.map{|z| f[z]} #> [["If", "Robert", "likes", "green", "beans,"], ["bears,", "John", "thinks", "Robert", "is", "strange."]] Harry