Created
May 8, 2012 17:10
-
-
Save brookr/2637453 to your computer and use it in GitHub Desktop.
Get a human-readable listing of what is in an array in Rails.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Array | |
| include ActionView::Helpers::TextHelper | |
| def to_inventory | |
| c = {} | |
| each { |e| c[e.class.name] = c[e.class.name].to_i + 1 } | |
| c.sort.map{ |k, v| pluralize(v, k) }.to_sentence | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment