module ActionView::Helpers::TextHelper

Public Instance Methods

pluralize(count, singular, plural = nil, &block) click to toggle source

Behaves exactly as the official `pluralize` helper except it allows you to pass an optional block that receives the current count and the pluralized word.

pluralize(2, 'person') do |count, word|
  "Yay #{count} #{word}"
end
# File lib/better_pluralize/helpers.rb, line 13
def pluralize(count, singular, plural = nil, &block)
  word = if (count == 1 || count =~ /^1(\.0+)?$/)
           singular
         else
           plural || singular.pluralize
         end

  safe_count = count || 0

  if block_given?
    capture safe_count, word, &block
  else
    "#{safe_count} #{word}"
  end
end