regex = Regexp.new(’((1|2|3|4|5|6|7|8|9))’)
Dir::foreach(Dir.getwd){ |filename|
n = regex=~filename
if n
newname = filename.sub(regex, “(0#{filename[n+1].chr})”)
f = File.open(filename, “wb+”)
f.rename(filename, newname)
f.close()
end
}
#################################################################
the error i get is this:
undefined method `rename’ for #<File:Until Further Notice (1) Wooden
Man.mp3>
from 1-to-01.rb:2:in 'foreach’
from 1-to-01.rb:2
OK, so what do I do now ?
“Ruby In A Nutshell” says: Methods can be defined that are associated
with specific o jects only. Such methods are called singleton methods.
This does not really help me though
svg% ri File::rename
----------------------------------------------------------- File::rename
File.rename(old_name, new_name) => 0
···
------------------------------------------------------------------------
Renames the given file to the new name. Raises a +SystemCallError+
if the file cannot be renamed.
File.rename("afile", "afile.bak") #=> 0
svg%
svg% ls b.rb c.rb
ls: c.rb: No such file or directory
b.rb*
svg%
svg% ruby -e 'File.rename("b.rb", "c.rb")'
svg%
svg% ls b.rb c.rb
ls: b.rb: No such file or directory
c.rb*
svg%