Skip to content

Instantly share code, notes, and snippets.

@sshaw
Last active September 10, 2016 23:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sshaw/b408f89b4128ddbeac28d2596fae6e39 to your computer and use it in GitHub Desktop.
Save sshaw/b408f89b4128ddbeac28d2596fae6e39 to your computer and use it in GitHub Desktop.
String#to_pluralizer: Create a pluralization Proc from a String
require "active_support/core_ext/string/inflections"
class String
def to_pluralizer
->(*a) { pluralize(*a) }
end
end
__END__
CUSTOMER = "customer".to_pluralizer
CUSTOMER[10] # customers
PRODUCT = "product".to_pluralizer
PRODUCT[10] # products
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment