Skip to content

Instantly share code, notes, and snippets.

@illbzo1
Created October 30, 2011 23:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save illbzo1/1326571 to your computer and use it in GitHub Desktop.
Save illbzo1/1326571 to your computer and use it in GitHub Desktop.
Madlibs Generator, Second Refactoring
def generate_mad_lib
puts "Bear with me. I'm going to need 16 singular nouns."
@nouns = []
16.times { @nouns << gets.chomp }
@nouns = @nouns.reverse
puts "Awesome, now I'm going to need 6 plural nouns."
@plural_nouns = []
6.times { @plural_nouns << gets.chomp }
@plural_nouns = @plural_nouns.reverse
puts "Ok, now let's collect some singular verbs. I'm looking for 7 of them."
@verbs = []
7.times { @verbs << gets.chomp }
@verbs = @verbs.reverse
puts "Almost done! Now we need 5 verbs in the present tense, such as running or leaping."
@present_verbs = []
5.times { @present_verbs << gets.chomp }
@present_verbs = @present_verbs.reverse
puts "Finally, I heard you like adjectives? Hey, me too! I'm going to need 4 of them."
@adjectives = []
4.times { @adjectives << gets.chomp }
@adjectives = @adjectives.reverse
end
generate_mad_lib()
require_relative 'mermaid'
def mermaid_lib
puts <<-LITTLE_MERMAID
Look at this #{@nouns.pop}, isn`t it neat?
Wouldn`t you think my collection`s complete?
Wouldn`t you think I`m the #{@nouns.pop}
The #{@nouns.pop} who has everything?
Look at this #{@nouns.pop}, treasures untold,
How many wonders can one #{@nouns.pop} hold?
#{@present_verbs.pop} around here, you`d think,
Sure, she`s got everything
I`ve got #{@plural_nouns.pop} and #{@plural_nouns.pop} a-plenty
I`ve got who`s-its and what`s-its galore
You #{@verbs.pop} thing-a-mabobs?
I`ve got 20.
But who cares? No #{@adjectives.pop} deal. I #{@verbs.pop} more!
I wanna be where the #{@plural_nouns.pop} are,
I wanna see, wanna see `em #{@present_verbs.pop},
Walkin` around on those
Whaddya call `em? Oh, #{@nouns.pop}!
#{@present_verbs.pop} your fins, you don`t get too far,
Legs are required for #{@present_verbs.pop}, dancin`,
Strollin` along down the,
What`s that word again? #{@nouns.pop}
Up where they #{@verbs.pop},
Up where they run,
Up where they stay all day in the #{@nouns.pop}!
Wanderin` free, wish I could be,
Part of that #{@nouns.pop}.
What would I give, if I could live,
Outta these #{@plural_nouns.pop}?
What would I pay, to spend a day,
#{@adjectives.pop} on the #{@nouns.pop}?
Betcha on #{@nouns.pop} they understand,
Bet they don`t reprimand their #{@plural_nouns.pop}
Bright young #{@plural_nouns.pop}, sick of #{@present_verbs.pop}
Ready to stand!
And ready to know what the #{@nouns.pop} know,
Ask `em #{@adjectives.pop} questions, and get some answers,
What`s a #{@nouns.pop}, and why does it,
What`s the word? #{@verbs.pop}!
When`s it my turn?
Wouldn`t I #{@verbs.pop}?
#{@verbs.pop} to explore that #{@nouns.pop} up above,
Out of #{@adjectives.pop} #{@nouns.pop}, wish I could be,
#{@verbs.pop} of that #{@nouns.pop}
LITTLE_MERMAID
end
mermaid_lib()
@jqr
Copy link

jqr commented Oct 31, 2011

Moar! What about something like this to Objectify:

madlib = MadLib.load('mermaid.madlib')
madlib.fill_in do |part_of_speech|
  puts "give me a #{part_of_speech}>"
  gets.chomp
end

puts madlib

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment