Looks like scan can return an unexpected results.
For example we'd like to remove directory "/dev/tools/"
then location /home/genadyp/dev/tools/ will be deleted:
>1.9.3-p327 :022 >   dir = "/dev/tools/"
 => "/dev/tools/" 
1.9.3-p327 :023 > path = "/home/genadyp/dev/tools/irb"
 => "/home/genadyp/dev/tools/irb" 
1.9.3-p327 :024 > path.scan(dir)
 => ["/dev/tools/"] 
1.9.3-p327 :025 > 

Is it OK?