Guest User

Untitled

a guest
Aug 10th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1.  
  2. # this is inside a Sinatra app, it's a verse game that helps kids learn bible verses by successively removing words as they progress. The words are replaced by form fields. The variable 'number' changes based on how far they've progressed (difficulty level).
  3. # phrase.sub!... is the critical part, it replaces random words from the verse, one at a time, with text fields. THe problem is that sometimes it replaces part of formfields that have already been placed, for example if the word was "in" or "put".
  4.  
  5.  
  6. def pick_n_replace ( words, number )
  7. phrase = @verse.body
  8. (number).times do
  9. random_word = words[rand(number)]
  10. phrase.sub!(random_word.to_s, "<input type='text' id='#{random_word.to_s}'>")
  11. words -= random_word
  12. end
  13. return phrase
  14. end
  15. @verse_layout = pick_n_replace(@verse.all_words, @verse.all_words.length)
Add Comment
Please, Sign In to add comment