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
# creates an empty array for the user's inventory | |
@inventory = [] | |
# this is the command prompt method | |
def prompt() | |
print "Enter command > " | |
end | |
# shows a list of viable commands when a user enters "help" at the command prompt | |
def help() |
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
class Game | |
def initialize(start) | |
@quips = [ | |
"You died. You kind of suck at this.", | |
"Nice job! You died again!", | |
"What a loser!", | |
"I have a small puppy that's better at this." | |
] | |
@start = start |
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
def prompt | |
print "> " | |
end | |
def generate_mad_lib | |
puts "Bear with me. I'm going to need 18 singular @nouns." | |
prompt; | |
@noun1 = gets.chomp() | |
@noun2 = gets.chomp() | |
@noun3 = gets.chomp() |
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
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." |
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
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 |
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
@counter = 0 | |
files = Dir.glob("*.madlib") | |
if files.size > 1 | |
puts "CHOOSE YOUR FILE:" | |
x = 0 | |
files.each do |file| | |
x += 1 | |
puts "#{x}. #{file}" |
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
files = Dir.glob("*.txt") | |
adjective_list1 = IO.readlines("adj1.txt") | |
adjective_list2 = IO.readlines("adj2.txt") | |
noun_list = IO.readlines("noun.txt") | |
prefix_list = IO.readlines("prefix.txt") | |
suffix_list = IO.readlines("suffix.txt") | |
rand1 = rand(adjective_list1.length) | |
rand2 = rand(adjective_list2.length) |
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
require 'yaml' | |
words = YAML::load(File.open('words.yml')) | |
loop do | |
puts "Generate new phrase? (y / n)" | |
input = gets.chomp() | |
unless input == "n" | |
new_phrase = %w[adj2 noun].map { |type| words[type].sample } | |
addition = rand(7) |
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
<form method="get" action="/input"> | |
<input type="text" name="input" /> | |
<input type="submit" value="Submit" /> | |
</form> |
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
# trying to set a method so I can use @input in other methods | |
class Input | |
def initialize(input) | |
@input = params[:input] | |
end | |
end | |
# collecting the input with a form here | |
get '/input' do | |
@input = params[:input] |
OlderNewer