Created
October 4, 2012 04:23
-
-
Save minitech/3831464 to your computer and use it in GitHub Desktop.
Getting a file's name and extension*s*
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://twitter.com/garybernhardt/status/253708758964903936 | |
def file_parts(filename) | |
parts = filename.split '.' | |
last_spaces = | |
parts.rindex do |part| | |
part.include? ' ' | |
end | |
[parts[0..last_spaces].join('.'), parts[last_spaces+1..-1]] | |
end | |
puts file_parts 'some.file.file name.with dots.html.markdown' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment