Skip to content

Instantly share code, notes, and snippets.

@illbzo1
Created October 30, 2011 17:30
Show Gist options
  • Save illbzo1/1326156 to your computer and use it in GitHub Desktop.
Save illbzo1/1326156 to your computer and use it in GitHub Desktop.
Refactored Madlibs generator
def generate_mad_lib
puts "Bear with me. I'm going to need 16 singular nouns."
@nouns = []
16.times { @nouns << gets.chomp }
puts "Awesome, now I'm going to need 6 plural nouns."
@plural_nouns = []
6.times { @plural_nouns << gets.chomp }
puts "Ok, now let's collect some singular verbs. I'm looking for 7 of them."
@verbs = []
7.times { @verbs << gets.chomp }
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 }
puts "You like adjectives? Hey, me too! I'm going to need 4 of them."
@adjectives = []
4.times { @adjectives << gets.chomp }
puts "And finally, we need just one number. Any number at all. Really!"
@number = gets.chomp()
end
generate_mad_lib()
require_relative 'mermaid'
def nouns
@nouns.pop
end
def plural_nouns
@plural_nouns.pop
end
def verbs
@verbs.pop
end
def present_verbs
@present_verbs.pop
end
def adjectives
@adjectives.pop
end
def mermaid_lib
puts <<-LITTLE_MERMAID
Look at this #{nouns}, isn`t it neat?
Wouldn`t you think my collection`s complete?
Wouldn`t you think I`m the #{nouns}
The #{nouns} who has everything?
Look at this #{nouns}, treasures untold,
How many wonders can one #{nouns} hold?
#{present_verbs} around here, you`d think,
Sure, she`s got everything
I`ve got #{plural_nouns} and #{plural_nouns} a-plenty
I`ve got who`s-its and what`s-its galore
You #{verbs} thing-a-mabobs?
I`ve got #{@number}
But who cares? No #{adjectives} deal. I #{verbs} more!
I wanna be where the #{plural_nouns} are,
I wanna see, wanna see `em #{present_verbs},
Walkin` around on those
Whaddya call `em? Oh, #{nouns}!
#{present_verbs} your fins, you don`t get too far,
Legs are required for #{present_verbs}, dancin`,
Strollin` along down the,
What`s that word again? #{nouns}
Up where they #{verbs},
Up where they run,
Up where they stay all day in the #{nouns}!
Wanderin` free, wish I could be,
Part of that #{nouns}.
What would I give, if I could live,
Outta these #{plural_nouns}?
What would I pay, to spend a day,
#{adjectives} on the #{nouns}?
Betcha on #{nouns} they understand,
Bet they don`t reprimand their #{plural_nouns}
Bright young #{plural_nouns}, sick of #{present_verbs}
Ready to stand!
And ready to know what the #{nouns} know,
Ask `em #{adjectives} questions, and get some answers,
What`s a #{nouns}, and why does it,
What`s the word? #{verbs}!
When`s it my turn?
Wouldn`t I #{verbs}?
#{verbs} to explore that #{nouns} up above,
Out of #{adjectives} #{nouns}, wish I could be,
#{verbs} of that #{nouns}
LITTLE_MERMAID
end
mermaid_lib()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment