Fixed it.
I passed a file name as follows at the start up file:

file_name = ARGV.first

in th terminal I just taped in:

ruby bin/my_ruby_file.rb data.txt

When hard coding te file name as folllows:

file_name = 'data.txt'

there was no problem.

After changing it to:

file_name = ARGV.pop

it worked with some modifications in the method reading the keyboard 
inputs:

def query_next_direction
      STDOUT.flush
      input = gets.chomp
      case input
      when DIRECTIONS[:left]
        self.x -= 1
      when DIRECTIONS[:up]
        self.y -= 1
      when DIRECTIONS[:right]
        self.x += 1
      when DIRECTIONS[:down]
        self.y += 1
      else
        puts "Unknown direction"
      end
    end

-- 
Posted via http://www.ruby-forum.com/.