Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在rails中获取文件扩展名时如何使用点?
现在我正在使用File.extname,但它保留了“。” 在给我名字之前
File.extname
这对你有用吗?
File.extname('something.jpg').delete('.') #=> 'jpg'
你甚至可以将它包装在一个助手中:
def file_extension(filename) File.extname(filename).delete('.') end file_extension('something.jpg') #=> 'jpg'