Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 1.47 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. module Ex25
  2.   def self.break_words(stuff)
  3.   #This function will break up words for us.
  4.   words - stuff.split(' ')
  5. words
  6.   end
  7.  
  8.   def self.sort_words(words)
  9.     #sort the words
  10.     words.sort( )
  11.   end
  12.  
  13.   def self.print_first_word(words)
  14.     #Prints the first word and shifts the others down by one.
  15.     word = words.shift( )
  16.     puts word
  17.   end
  18.  
  19.   def self.print_last_word(words)
  20.     #Prints the last word after popping it off the end.
  21.     word = words.pop( )
  22.     puts word
  23.   end
  24.  
  25.   def self.sort_sentence(sentence)
  26.     #Takes in a full sentence and returns the words sorted.
  27.     words = break_words(sentence)
  28.     sort words(words)
  29.   end
  30.  
  31.   def self.print_first_and_last(sentence)
  32.     #Prints the first and last words of the sentence
  33.     words = break_words(sentence)
  34.     print_first_words(words)
  35.     print_last_word(words)
  36.   end
  37.  
  38.   def self.print_first_and_last_sorted(sentence)
  39.     #Sorts the words then prints the first and last one.
  40.     words = sort_sentence(sentence)
  41.     print_first_word(words)
  42.     print_last_word(words)
  43.   end
  44. end
  45.  
  46.  
  47. I get:
  48.  
  49. Morgans-Computer:mystuff Morgan$ irb
  50. ruby-1.9.2-p290 :001 > require 'ex25'
  51. LoadError: no such file to load -- ex25
  52.         from /Users/Morgan/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
  53.         from /Users/Morgan/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
  54.         from (irb):1
  55.         from /Users/Morgan/.rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `<main>'
  56. ruby-1.9.2-p290 :002 >