Skip to content

Instantly share code, notes, and snippets.

@timothyekl
Created July 14, 2011 13:52
Show Gist options
  • Save timothyekl/1082493 to your computer and use it in GitHub Desktop.
Save timothyekl/1082493 to your computer and use it in GitHub Desktop.
Ruby: split string, respecting double quotes
class String
def smart_split
sa = self.split(/"/).collect { |x| x.strip }
return (1..sa.length).zip(sa).collect { |i,x| (i&1).zero? ? x : x.split }.flatten
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment