lib/game.rb
# ignore comment line "#" 
# split command line into command and argument, and execute it.
ignore comment line "#"
split command line into command and argument, and execute it.
ignore comment line " # " split command line into command and argument and execute it .
def process command
        if command.strip[0] == "#"
          puts command
          return
        end
        instruction = command.split(" ",2)
        command_type = instruction[0].downcase
        begin
          if instruction[1].nil?
            @command.send(command_type)
          else
            args = instruction[1].split(",").map{|var| var.strip}
            @command.send(command_type, *args)
          end
        rescue ArgumentError
          puts "=> Wrong number of arguments, illegal \"#{instruction[1]}\" for "\
           + command_type
        rescue NoMethodError
          puts "=> Unknown command: "+command_type
        end
      end
def process command if command . strip [ 0 ] == "#" puts command return end instruction = command . split ( " " , 2 ) command_type = instruction [ 0 ] . downcase begin if instruction [ 1 ] . nil? @command . send ( command_type ) else args = instruction [ 1 ] . split ( "," ) . map { | var | var . strip } @command . send ( command_type , * args ) end rescue ArgumentError puts "=> Wrong number of arguments, illegal \"#{instruction[1]}\" for " + command_type rescue NoMethodError puts "=> Unknown command: " + command_type end end
ignore comment line "#"
split command line into command and argument, and execute it.
ignore comment line " # " split command line into command and argument and execute it .
# ignore comment line and puts out # ["place", "1, 2, north"] # 'place' arguments validation is handled in command Class. # the other commands should have no input, is validated in this methods
command
<not_specific>