spacepaste

  1.  
  2. #!/bin/ruby
  3. module Ex25
  4. # This function will break up words for us.
  5. def self.break_words(stuff)
  6. words = stuff.split(" ")
  7. words
  8. end
  9. # Sorts the words.
  10. def self.sort_words(words)
  11. words = words.sort()
  12. words
  13. end
  14. # Prints the first word after shifting one back.
  15. def self.print_first_word(words)
  16. word = words.shift()
  17. puts word
  18. end
  19. # Prints the last word after popping it off.
  20. def self.print_last_word(words)
  21. word = words.pop()
  22. puts word
  23. end
  24. # Takes in a full sentence and returns the sorted words.
  25. def self.sort_sentence(sentence)
  26. words = break_words(sentence)
  27. words = sort_words(words)
  28. words
  29. end
  30. # Prints the first and last words of the sentence.
  31. def self.print_first_last(sentence)
  32. words = break_words(sentence)
  33. print_first_word(words)
  34. print_last_word(words)
  35. end
  36. # Sorts the words then prints the first and last one.
  37. def self.print_first_last_sorted(sentence)
  38. words = sort_sentence(sentence)
  39. print_first_word(words)
  40. print_last_word(words)
  41. end
  42. # Break it, pop a couple off the end and add fucker to the end, than return new sentence.
  43. def self.add_fucker(sentence)
  44. words = break_words(sentence)
  45. word = 2.times do words.pop() end
  46. sentence = words.join(" ")
  47. sentence = sentence + " fuckers."
  48. puts sentence
  49. sentence
  50. end
  51. # Shift 4 off the beginning, add death and put back together. Return new sentence.
  52. def self.add_death(sentence)
  53. words = break_words(sentence)
  54. word = 4.times do words.shift() end
  55. sentence = words.join(" ")
  56. death = "Death will "
  57. sentence = death + sentence
  58. puts sentence
  59. sentence
  60. end
  61. # Combines the two end changes above and prints out.
  62. def self.change_sentence(sentence)
  63. sentence = add_fucker(sentence)
  64. sentence
  65. puts "\n"
  66. puts "Than the other half:"
  67. sentence = add_death(sentence)
  68. puts "\n"
  69. sentence
  70. end
  71. end
  72. puts "\n"
  73. puts "Let's practice everyfuckingthing."
  74. puts "\n"
  75. poem = <<END
  76. \tThe lovely world
  77. with logic so firmly planted
  78. cannot discern \n the needs of love
  79. nor comprehend passion from intuition
  80. and requires an explanation
  81. \n\t\twhere there is none.
  82. END
  83. puts "--------------"
  84. puts poem
  85. puts "--------------"
  86. puts "\n"
  87. five = 10 - 2 + 3 - 6
  88. puts "This should say #{five}."
  89. puts "\n"
  90. def secret_formula(started)
  91. jelly_beans = started
  92. jars = jelly_beans / 10
  93. crates = jars / 10
  94. return jelly_beans, jars, crates
  95. end
  96. start_point = 10000
  97. puts "start point is: #{start_point}"
  98. (beans, jars, crates) = secret_formula(start_point)
  99. puts "With a starting point of: #{start_point}"
  100. puts "we'd have #{beans} beans, #{jars} jars and #{crates} crates."
  101. puts "\n"
  102. start_point = start_point / 10
  103. puts "start point is: #{start_point}"
  104. puts "\n"
  105. puts "Now fer' the other way:"
  106. puts "With a starting point of: #{start_point}"
  107. puts "we'd have %s beans, %s jars and %s crates." % secret_formula(start_point)
  108. puts "\n"
  109. sentence = "fuck all good things come to those who wait."
  110. puts sentence
  111. puts "\n"
  112. words = Ex25.break_words(sentence)
  113. sorted_words = Ex25.sort_words(words)
  114. puts "print first than last:"
  115. Ex25.print_first_word(words)
  116. Ex25.print_last_word(words)
  117. puts "\n"
  118. puts "Print first and last sorted:"
  119. Ex25.print_first_word(sorted_words)
  120. Ex25.print_last_word(sorted_words)
  121. sorted_words = Ex25.sort_sentence(sentence)
  122. puts "\n"
  123. puts "Print first and last:"
  124. Ex25.print_first_last(sentence)
  125. puts "\n"
  126. puts "Print first and last sorted:"
  127. Ex25.print_first_last_sorted(sentence)
  128. puts "\n"
  129. puts "pop two off the end and add fuckers:"
  130. Ex25.add_fucker(sentence)
  131. puts "\n"
  132. puts "shift four off the beginning and add death:"
  133. Ex25.add_death(sentence)
  134. puts "\n"
  135. puts "Print the sentence with both changes:"
  136. puts "First we add fuckers:"
  137. Ex25.change_sentence(sentence)
  138.