- #!/bin/ruby
- module Ex25
- # This function will break up words for us.
- def self.break_words(stuff)
- words = stuff.split(" ")
- words
- end
- # Sorts the words.
- def self.sort_words(words)
- words = words.sort()
- words
- end
- # Prints the first word after shifting one back.
- def self.print_first_word(words)
- word = words.shift()
- puts word
- end
- # Prints the last word after popping it off.
- def self.print_last_word(words)
- word = words.pop()
- puts word
- end
- # Takes in a full sentence and returns the sorted words.
- def self.sort_sentence(sentence)
- words = break_words(sentence)
- words = sort_words(words)
- words
- end
- # Prints the first and last words of the sentence.
- def self.print_first_last(sentence)
- words = break_words(sentence)
- print_first_word(words)
- print_last_word(words)
- end
- # Sorts the words then prints the first and last one.
- def self.print_first_last_sorted(sentence)
- words = sort_sentence(sentence)
- print_first_word(words)
- print_last_word(words)
- end
- # Break it, pop a couple off the end and add fucker to the end, than return new sentence.
- def self.add_fucker(sentence)
- words = break_words(sentence)
- word = 2.times do words.pop() end
- sentence = words.join(" ")
- sentence = sentence + " fuckers."
- puts sentence
- sentence
- end
- # Shift 4 off the beginning, add death and put back together. Return new sentence.
- def self.add_death(sentence)
- words = break_words(sentence)
- word = 4.times do words.shift() end
- sentence = words.join(" ")
- death = "Death will "
- sentence = death + sentence
- puts sentence
- sentence
- end
- # Combines the two end changes above and prints out.
- def self.change_sentence(sentence)
- sentence = add_fucker(sentence)
- sentence
- puts "\n"
- puts "Than the other half:"
- sentence = add_death(sentence)
- puts "\n"
- sentence
- end
- end
- puts "\n"
- puts "Let's practice everyfuckingthing."
- puts "\n"
- poem = <<END
- \tThe lovely world
- with logic so firmly planted
- cannot discern \n the needs of love
- nor comprehend passion from intuition
- and requires an explanation
- \n\t\twhere there is none.
- END
- puts "--------------"
- puts poem
- puts "--------------"
- puts "\n"
- five = 10 - 2 + 3 - 6
- puts "This should say #{five}."
- puts "\n"
- def secret_formula(started)
- jelly_beans = started
- jars = jelly_beans / 10
- crates = jars / 10
- return jelly_beans, jars, crates
- end
- start_point = 10000
- puts "start point is: #{start_point}"
- (beans, jars, crates) = secret_formula(start_point)
- puts "With a starting point of: #{start_point}"
- puts "we'd have #{beans} beans, #{jars} jars and #{crates} crates."
- puts "\n"
- start_point = start_point / 10
- puts "start point is: #{start_point}"
- puts "\n"
- puts "Now fer' the other way:"
- puts "With a starting point of: #{start_point}"
- puts "we'd have %s beans, %s jars and %s crates." % secret_formula(start_point)
- puts "\n"
- sentence = "fuck all good things come to those who wait."
- puts sentence
- puts "\n"
- words = Ex25.break_words(sentence)
- sorted_words = Ex25.sort_words(words)
- puts "print first than last:"
- Ex25.print_first_word(words)
- Ex25.print_last_word(words)
- puts "\n"
- puts "Print first and last sorted:"
- Ex25.print_first_word(sorted_words)
- Ex25.print_last_word(sorted_words)
- sorted_words = Ex25.sort_sentence(sentence)
- puts "\n"
- puts "Print first and last:"
- Ex25.print_first_last(sentence)
- puts "\n"
- puts "Print first and last sorted:"
- Ex25.print_first_last_sorted(sentence)
- puts "\n"
- puts "pop two off the end and add fuckers:"
- Ex25.add_fucker(sentence)
- puts "\n"
- puts "shift four off the beginning and add death:"
- Ex25.add_death(sentence)
- puts "\n"
- puts "Print the sentence with both changes:"
- puts "First we add fuckers:"
- Ex25.change_sentence(sentence)