Skip to content

Instantly share code, notes, and snippets.

@minitech
Created October 4, 2012 04:23
Show Gist options
  • Save minitech/3831464 to your computer and use it in GitHub Desktop.
Save minitech/3831464 to your computer and use it in GitHub Desktop.
Getting a file's name and extension*s*
# 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