Skip to content

Instantly share code, notes, and snippets.

@j3ck
Last active August 29, 2015 14:13
Show Gist options
  • Select an option

  • Save j3ck/8a48ea4e26b0f8353867 to your computer and use it in GitHub Desktop.

Select an option

Save j3ck/8a48ea4e26b0f8353867 to your computer and use it in GitHub Desktop.
"abcda".chars.group_by(&:chr).map{|k,v| {k => v.size}}
"abca".chars.inject(Hash.new(0)){|h, c| h[c] +=1; h}
"abca".chars.inject(Hash.new(0)){|h, c| h[c] +=1}
"abca".chars.inject(Hash.new(0)){|h, c| puts h; h[c] +=1; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment