Skip to content

Commit

Permalink
adding 34, 35, 39, 40
Browse files Browse the repository at this point in the history
  • Loading branch information
lancelakey committed Dec 30, 2011
1 parent 86d8122 commit 4e0546a
Show file tree
Hide file tree
Showing 9 changed files with 685 additions and 0 deletions.
218 changes: 218 additions & 0 deletions ex34.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,221 @@
puts animals.last


#~ > irb
#>>
#?>
#?>
#?> dogs = ['beagle', 'dauschund', 'great dane']
#=> ["beagle", "dauschund", "great dane"]
#>> dogs
#=> ["beagle", "dauschund", "great dane"]
#>>
#?>
#?>
#?>
#?> dogs.length
#=> 3
#>>
#?>
#?>
#?> dogs[0]
#=> "beagle"
#>>
#?>
#?>
#?>
#?> dogs[0].class
#=> String
#>>
#?>
#?>
#?> dogs[0].swapcase
#=> "BEAGLE"
#>>
#?>
#?>
#?>
#?> dogs.swapcase
#NoMethodError: undefined method `swapcase' for ["beagle", "dauschund", "great dane"]:Array
# from (irb):28
#>> dogs[-1]
#=> "great dane"
#>>
#?>
#?>
#?> dogs.each { |i
#>>
#
#^C
#>>
#?>
#?> dogs.each { |dog| puts dog }
#beagle
#dauschund
#great dane
#=> ["beagle", "dauschund", "great dane"]
#>>
#?>
#?>
#?>
#?> dogs.each { |dog| puts dog }.swapcase
#beagle
#dauschund
#great dane
#NoMethodError: undefined method `swapcase' for ["beagle", "dauschund", "great dane"]:Array
# from (irb):41
#>>
#?>
#?> dogs.each { |dog| puts dog.swapcase }
#BEAGLE
#DAUSCHUND
#GREAT DANE
#=> ["beagle", "dauschund", "great dane"]
#>>
#?>
#?>
#?>
#?>
#?> dogs.each { |dog| puts dog.reverse.swapcase }
#ELGAEB
#DNUHCSUAD
#ENAD TAERG
#=> ["beagle", "dauschund", "great dane"]
#>>
#?>
#?>
#?>
#?>
#?>
#?>
#?> dogs
#=> ["beagle", "dauschund", "great dane"]
#>>
#?>
#?>
#?>
#?> dogs.each { |dog| puts dog.class }
#String
#String
#String
#=> ["beagle", "dauschund", "great dane"]
#>>
#?>
#?>
#?> dogs.each { |dog| puts dog.class; puts dog }
#String
#beagle
#String
#dauschund
#String
#great dane
#=> ["beagle", "dauschund", "great dane"]
#>>
#?>
#?> dogs.each { |dog| put dog.class; put dog }
#NoMethodError: undefined method `put' for main:Object
# from (irb):70
# from (irb):70:in `each'
# from (irb):70
#>> dogs.each { |dog| put dog.class; puts dog }
#NoMethodError: undefined method `put' for main:Object
# from (irb):71
# from (irb):71:in `each'
# from (irb):71
#>>
#?>
#?>
#?> dogs.each { |dog| print dog.class; put dog }
#StringNoMethodError: undefined method `put' for main:Object
# from (irb):75
# from (irb):75:in `each'
# from (irb):75
#>>
#?>
#?>
#?> dogs.each { |dog| print dog.class; puts dog }
#Stringbeagle
#Stringdauschund
#Stringgreat dane
#=> ["beagle", "dauschund", "great dane"]
#>>
#?>
#?>
#?> dogs.each { |dog| print dog.class; print " " puts dog }
#SyntaxError: compile error
#(irb):83: syntax error, unexpected tIDENTIFIER, expecting '}'
#dogs.each { |dog| print dog.class; print " " puts dog }
# ^
# from (irb):83
#>> dogs.each { |dog| print dog.class; print " "; puts dog }
#String beagle
#String dauschund
#String great dane
#=> ["beagle", "dauschund", "great dane"]
#>> dogs.each { |dog| print dog.class; print " "; puts dog }
#String beagle
#String dauschund
#String great dane
#=> ["beagle", "dauschund", "great dane"]
#>>
#?>
#?>
#?>
#?>
#?> dogs.each { |dog| print dog.class; print " "; puts dog.reverse.swapcase }
#String ELGAEB
#String DNUHCSUAD
#String ENAD TAERG
#=> ["beagle", "dauschund", "great dane"]
#>>
#?>
#?>
#?>
#?>
#?>
#?>
#?>
#?>
#?> dogs.first
#=> "beagle"
#>> dogs.first.class
#=> String
#>>
#?>
#?>
#?> dogs.first.reverse
#=> "elgaeb"
#>>
#?>
#?>
#?> dogs.first.class.reverse
#NoMethodError: undefined method `reverse' for String:Class
# from (irb):110
#>>
#?>
#?>
#?> dogs.first.reverse.swapcase
#=> "ELGAEB"
#>>
#?>
#?>
#?>
#?>
#?>
#?>
#?>
#?> dogs[0]
#=> "beagle"
#>>
#?>
#?>
#?>
#?> puts dogs
#beagle
#dauschund
#great dane
#=> nil
#>> puts dogs[0]
#beagle
#=> nil
#>>
87 changes: 87 additions & 0 deletions ex35.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/usr/bin/env ruby

def prompt()
print "> "
end

def gold_room()
puts "This room is full of gold. How much do you take?"

prompt; next_move = gets.chomp
if next_move.include? "0" or next_move.include? "1"
how_much = next_move.to_i()
else
dead("Man, learn to type a number.")
end

if how_much < 50
puts "Nice, you're not greedy, you win!"
Process.exit(0)
else
dead("You greedy bastard!")
end
end

def bear_room()
puts "There is a bear here."
puts "The bear has a bunch of honey."
puts "The fat bear is in front of another door."
puts "How are you going to move the bear?"
bear_moved = false

while true
prompt; next_move = gets.chomp

if next_move == "take honey"
dead("The bear looks at you then slaps your face off.")
elsif next_move == "taunt bear" and not bear_moved
puts "The bear has moved from the door. You can go through it now."
bear_moved = true
elsif next_move == "taunt bear" and bear_moved
dead("The bear gets pissed off and chews your leg off.")
elsif next_move == "open door" and bear_moved
gold_room()
else
puts "I got no idea what that means."
end
end
end

def cthulu_room()
puts "Here you see the great evil Cthulu"
puts "He stares at you and you go insane."
puts "Do you flee or eat your head?"

prompt; next_move = gets.chomp

if next_move.include? "flee"
start()
elsif next_move.include? "head"
dead("Well that was tasty!")
else
cthulu_room()
end
end

def dead(why)
puts "#{why} Good job!"
Process.exit(0)
end

def start()
puts "You are in a dark room."
puts "There is a door to your left and right."
puts "Which one do you take?"

prompt; next_move = gets.chomp

if next_move == "left"
bear_room()
elsif next_move == "right"
cthulu_room()
else
dead("You stumble around the room until you starve.")
end
end

start()
87 changes: 87 additions & 0 deletions ex35_4.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/usr/bin/env ruby

def prompt()
print "> "
end

def gold_room()
puts "This room is full of gold. How much do you take?"

prompt; next_move = gets.chomp.to_i
if next_move > 1
how_much = next_move
else
dead("Man, learn to type a number... and 0 is for luzers")
end

if how_much < 50
puts "Nice, you're not greedy, you win!"
Process.exit(0)
else
dead("You greedy bastard!")
end
end

def bear_room()
puts "There is a bear here."
puts "The bear has a bunch of honey."
puts "The fat bear is in front of another door."
puts "How are you going to move the bear?"
bear_moved = false

while true
prompt; next_move = gets.chomp

if next_move == "take honey"
dead("The bear looks at you then slaps your face off.")
elsif next_move == "taunt bear" and not bear_moved
puts "The bear has moved from the door. You can go through it now."
bear_moved = true
elsif next_move == "taunt bear" and bear_moved
dead("The bear gets pissed off and chews your leg off.")
elsif next_move == "open door" and bear_moved
gold_room()
else
puts "I got no idea what that means."
end
end
end

def cthulu_room()
puts "Here you see the great evil Cthulu"
puts "He stares at you and you go insane."
puts "Do you flee or eat your head?"

prompt; next_move = gets.chomp

if next_move.include? "flee"
start()
elsif next_move.include? "head"
dead("Well that was tasty!")
else
cthulu_room()
end
end

def dead(why)
puts "#{why} Good job!"
Process.exit(0)
end

def start()
puts "You are in a dark room."
puts "There is a door to your left and right."
puts "Which one do you take?"

prompt; next_move = gets.chomp

if next_move == "left"
bear_room()
elsif next_move == "right"
cthulu_room()
else
dead("You stumble around the room until you starve.")
end
end

start()
Loading

0 comments on commit 4e0546a

Please sign in to comment.