Skip to content

Instantly share code, notes, and snippets.

@sporkmonger
Created November 15, 2008 20:53
Show Gist options
  • Save sporkmonger/25325 to your computer and use it in GitHub Desktop.
Save sporkmonger/25325 to your computer and use it in GitHub Desktop.
Split Weirdness
# WHY?
"/foo/bar/baz".split("/")
# => ["", "foo", "bar", "baz"]
"/foo/bar/baz/".split("/")
# => ["", "foo", "bar", "baz"]
"foo/bar/baz/".split("/")
# => ["foo", "bar", "baz"]
# What's the best way to get this result?
"/foo/bar/baz".split_alternative("/")
# => ["", "foo", "bar", "baz"]
"/foo/bar/baz/".split_alternative("/")
# => ["", "foo", "bar", "baz", ""]
"foo/bar/baz/".split_alternative("/")
# => ["foo", "bar", "baz", ""]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment