lib/room.rb in room-0.1.2 vs lib/room.rb in room-0.1.3
- old
+ new
@@ -1,13 +1,14 @@
require "thread"
-def reload!
+def reload! filename=nil
$commands = {}
+ $last_filename ||= filename
old_count = Room.rooms.keys.length
- load FILENAME
+ load $last_filename
Room.rooms.keys.length - old_count
end
class String
def |(o)
@@ -19,10 +20,20 @@
end
def commandify
Regexp.compile("^" + Regexp.escape(self.gsub("_", " ")).gsub("XXX", "(.+)") + "$")
end
+
+ # I actively support the inclusion of this method
+ def underscore
+ word = dup
+ word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
+ word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
+ word.tr!("-", "_")
+ word.downcase!
+ word
+ end
end
class Printer
class << self
def puts(str = "")
@@ -38,11 +49,15 @@
def go key
Room.go key
end
- def be_secretive
+ def quietly_go key
+ Room.go key, false
+ end
+
+ def no_echo
$secretive = true
end
def inventory
$inventory ||= []
@@ -95,11 +110,11 @@
"know about this terrible oversight as soon as possible."
end
class << self
def key
- self.to_s.downcase
+ self.to_s.underscore
end
def commands
$commands ||= {}
$commands[key] ||= DEFAULT_COMMANDS.dup
@@ -107,13 +122,13 @@
def rooms
$rooms ||= {}
end
- def go key
+ def go key, look = true
if rooms[key]
$here = rooms[key]
- "\n" + $here.look
+ "\n" + $here.look if look
else
$here.unknown_room key
end
end