Created
December 14, 2012 03:17
-
-
Save big-samantha/4282427 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Ex25 | |
def self.break_words(stuff) | |
# This functino will break up words for us. | |
words = stuff.split(' ') | |
words | |
end | |
def self.sort_words(words) | |
# Sorts the words. | |
words.sort() | |
end | |
def self.print_first_word(words) | |
# Prints the first word and shifts the others down by one. | |
word = words.shift() | |
puts word | |
end | |
def self.print_last_word(words) | |
# Prints the last word after popping it off the end. | |
word = words.pop() | |
puts word | |
end | |
def self.sort_sentence(sentence) | |
# Takes in a full sentence and returns the sorted words. | |
words = break_words(sentence) | |
sort_words(words) | |
end | |
def self.print_first_and_last(sentence) | |
# Prints the first and last words of the sentence. | |
words = break_words(sentence) | |
print_first_word(words) | |
print_last_word(words) | |
end | |
def self.print_first_and_last_sorted(sentence) | |
# Sorts the words then prints the first and last one. | |
words = sort_sentence(sentence) | |
print_first_word(words) | |
print_last_word(words) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment