Why don't match and scan work properly in AR?

I’m trying this in the save method of an ActiveRecord object:

def save
f = self.file

self.file_extension = f.match(/\.(.+?)$/)[1] if self.file # returns 

entire file name
self.file_extension = f.scan(/.(.+?)$/)[0][0] if self.file #
returns entire file name
self.file_extension = f[f.rindex(’.’)+1, f.length] # works!

super

if self.file
  FileUtils.cp(self.file, self.file_path)
  FileUtils.chmod(FILE_MODE, self.file_path)
end

end

As you can see by my comments, the first two return the entire file
name. I’ve done the same two equivalent lines in script/console and they
both return the extension I’m looking for. Any idea why they behave
differently in ActiveRecord?

Thanks,
Joe