Skip to content

Commit

Permalink
added comments about initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
lancelakey committed Feb 8, 2012
1 parent 848eb2c commit 17d7a9a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions ex42.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

class Game

# Whenever Ruby creates a new object, it looks for a method named initialize and executes it.
# Arguments supplied to .new() are delivered to initialize()
# In this script the argument :central_corridor is supplied to initialize(start)
# a_game = Game.new(:central_corridor)
def initialize(start)
@quips = [
"you died. You kinda suck at this.",
Expand All @@ -11,6 +15,10 @@ def initialize(start)
]
@start = start
puts "in init @start = " + @start.inspect
# Here we are calling the method inspect on @start which is a symbol
# @start has been assigned the symbol :central_corridor
# @start.inspect returns :central_corridor
# The method inspect returns a string containing a human-readable representaiton of the object it is being called upon
end

def prompt()
Expand All @@ -24,6 +32,9 @@ def play()
while true
puts "\n----------"
room = method(next_room)
puts "PUTS ROOM INSPECT AND CLASS"
puts room.inspect
puts room.class
next_room = room.call()
end
end
Expand Down Expand Up @@ -182,6 +193,12 @@ def escape_pod()
end
end

# Create a new instance of the Class "Game"
# Supply the initialize method with the argument :central_corridor
# Assign this to the object a_game
a_game = Game.new(:central_corridor)

# Call the method play on the object a_game
# The method play
a_game.play()

0 comments on commit 17d7a9a

Please sign in to comment.