daily pastebin goal
22%
SHARE
TWEET

Untitled

a guest Aug 10th, 2018 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top