Skip to content

Instantly share code, notes, and snippets.

@brookr
Created May 8, 2012 17:10
Show Gist options
  • Select an option

  • Save brookr/2637453 to your computer and use it in GitHub Desktop.

Select an option

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.
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