Guest User

Untitled

a guest
Feb 20th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #!/usr/bin/env ruby -w
  2.  
  3. class Array
  4. def rand
  5. fetch(Kernel.rand(size))
  6. end
  7. end
  8.  
  9. characters = %w[James Ruby]
  10. sentence_structure = [ "S falls in love with O.",
  11. "S (slays|kills) O(.|.|.|!)",
  12. "S cries." ]
  13.  
  14. output = String.new
  15. (ARGV.shift || 5).to_i.times do
  16. sentence = sentence_structure.rand.gsub(/\b[SO]\b/) { characters.rand }
  17. output << " " << sentence.gsub(/\([^()|]+(?:\|[^()|]+)+\)/) do |choices|
  18. choices[1..-2].split("|").rand
  19. end
  20. end
  21.  
  22. puts output.strip.gsub(/(.{1,80}|\S{81,})(?: +|$\n?)/, "\\1\n")
Add Comment
Please, Sign In to add comment