Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 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).
- # 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".
- def pick_n_replace ( words, number )
- phrase = @verse.body
- (number).times do
- random_word = words[rand(number)]
- phrase.sub!(random_word.to_s, "<input type='text' id='#{random_word.to_s}'>")
- words -= random_word
- end
- return phrase
- end
- @verse_layout = pick_n_replace(@verse.all_words, @verse.all_words.length)
Add Comment
Please, Sign In to add comment