Extracting components of a filename I have a string str ="/Users/user/Desktop/task/U6342_Account_20150112.txt"

I need return only U6342_Account_20150112 as an array ['U6342','Account','20150112']

I did 

str.split('/')[-1].gsub('.txt','').split('_')


which gives me ['U6342','Account','20150112']

Is there any more convenient solution to do it?
The string looks like a filename, so you should use the library functions for handling file paths instead of rolling your own.

File.basename(str, '.txt').split('_')