FakeProfilePictures::Photo.all_large_names_2x
(定义如下)返回一个绝对路径名数组,但是当我Dir["picture_*@2x.*"]
从正确的目录中执行时irb
,我只得到基本名称(我想要的)。获得基本名称的最佳方法是什么?我知道我可以通过添加.map { |f| File.basename(f) }
如评论中所示来做到这一点,但有没有更简单/更好/更快/更强的方法?
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