Skip to content

Instantly share code, notes, and snippets.

@craigweston
Created August 19, 2015 17:21
Show Gist options
  • Save craigweston/7d26055d5cec0e84a91c to your computer and use it in GitHub Desktop.
Save craigweston/7d26055d5cec0e84a91c to your computer and use it in GitHub Desktop.
One liner that converts array of names from "Smith, Joe" format to "Joe Smith"
names = ['Mike Smith', 'McDonald, John', 'Jill Doe']
names.map { |e| e.split(/,\s*/).reverse!.join(' ') }
# => ["Mike Smith", "John McDonald", "Jill Doe"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment