
Untitled
By: a guest on
May 8th, 2012 | syntax:
None | size: 1.47 KB | hits: 12 | expires: Never
module Ex25
def self.break_words(stuff)
#This function will break up words for us.
words - stuff.split(' ')
words
end
def self.sort_words(words)
#sort 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 words sorted.
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_words(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
I get:
Morgans-Computer:mystuff Morgan$ irb
ruby-1.9.2-p290 :001 > require 'ex25'
LoadError: no such file to load -- ex25
from /Users/Morgan/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/Morgan/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from (irb):1
from /Users/Morgan/.rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `<main>'
ruby-1.9.2-p290 :002 >