Couple issues with this that I see, sorted hopefully in the order of interpreter failures:
1) You don't need that end. There's nothing opening it - no if, while, begin block, etc. 'kend' is the symbol for a lexicographical end - that is, an end written by the programmer. $end is the symbol that means end of file. Your error message is saying, "You typed end, but I'm expecting the end of the file." So delete line 4.
That MAY fix your problems; if not:
2) str (the File object for rename.rb) is opened for writing, but you're trying to read. Change line 1 to
str = File.open(
Or you may get an IOError on that 'read' called on an object only opened for writing.
3) Depending on your version, you may have overwritten rename.rb and replaced it with an empty file, by opening it for writing. That can default to File.new(), and because the program ended without writing anything, it's a blank file.
Hope that helps.