【发布时间】:2011-08-14 05:23:16
【问题描述】:
FakeProfilePictures::Photo.all_large_names_2x(定义如下)返回一个绝对路径名数组,但是当我从irb 中的正确目录执行Dir["picture_*@2x.*"] 时,我只能得到基本名称(我想要的)。获得基本名称的最佳方法是什么?我知道我可以通过添加.map { |f| File.basename(f) } 来做到这一点,如评论中所示,但有没有更简单的/better/faster/stronger 方式?
module FakeProfilePictures
class Photo
DIR = File.expand_path(File.join(File.dirname(__FILE__), "photos"))
# ...
def self.all_large_names_2x
@@all_large_names_2x ||= Dir[File.join(DIR, "picture_*@2x.*")] # .map { |f| File.basename(f) }
end
end
end
【问题讨论】:
标签: ruby absolute-path dir