ruby rookie needs help with mtime method of File

Barry Kimelman <[email protected]> Thu, 22 Aug 2019 13:53:31 -0600
Newsgroups gmane.comp.lang.ruby.general
Message-ID <CAD9yHXPpZK0rkSm2q5ryvec39bKfuG8PpUk0vhEcgg81zAQ0bA@mail.gmail.com>
I was looking at an example of the "mtime" method for a file and when I ran
the example I received the following traceback

C:\barry\ruby>ruby dir3-glob.rb
backtick1.rb
Traceback (most recent call last):
        2: from dir3-glob.rb:3:in `<main>'
        1: from dir3-glob.rb:3:in `glob'
dir3-glob.rb:6:in `block in <main>': undefined method `mtime' for
"backtick1.rb":String (NoMethodError)

The source of my script is as follows
     1 #!C:\Ruby\bin\ruby.exe -w
     2
     3 Dir.glob("*.rb") {|file|
     4  # do something with the file here
     5  puts file
     6  mtime = file.mtime
     7  new_filename = "#{mtime.year}-#{mtime.month}-#{mtime.day}.wma"
     8  puts "Renaming #{filename} to #{new_filename} ..."
     9 }

What have I done wrong?

==================

Barry Kimelman
Winnipeg, Manitoba, Canada

<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
Virus-free.
www.avast.com
<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>


Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>