From d046390c324142afffbf105075a1f4998c149c14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Tue, 28 Mar 2017 18:02:00 -0400 Subject: Use keyword arguments instead of hash --- .../lib/active_support/core_ext/string/inflections.rb | 8 ++++---- activesupport/lib/active_support/inflector/methods.rb | 12 +++++++----- 2 files changed, 11 insertions(+), 9 deletions(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/core_ext/string/inflections.rb b/activesupport/lib/active_support/core_ext/string/inflections.rb index 539e874368..b27cfe53f4 100644 --- a/activesupport/lib/active_support/core_ext/string/inflections.rb +++ b/activesupport/lib/active_support/core_ext/string/inflections.rb @@ -109,8 +109,8 @@ class String # 'man from the boondocks'.titleize # => "Man From The Boondocks" # 'x-men: the last stand'.titleize # => "X Men: The Last Stand" # 'string_ending_with_id'.titleize(keep_id_suffix: true) # => "String Ending With Id" - def titleize(options = {}) - ActiveSupport::Inflector.titleize(self, options) + def titleize(keep_id_suffix: false) + ActiveSupport::Inflector.titleize(self, keep_id_suffix: keep_id_suffix) end alias_method :titlecase, :titleize @@ -224,8 +224,8 @@ class String # 'author_id'.humanize(capitalize: false) # => "author" # '_id'.humanize # => "Id" # 'author_id'.humanize(keep_id_suffix: true) # => "Author Id" - def humanize(options = {}) - ActiveSupport::Inflector.humanize(self, options) + def humanize(capitalize: true, keep_id_suffix: false) + ActiveSupport::Inflector.humanize(self, capitalize: capitalize, keep_id_suffix: keep_id_suffix) end # Converts just the first character to uppercase. diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb index 737ea5666e..1b089a7538 100644 --- a/activesupport/lib/active_support/inflector/methods.rb +++ b/activesupport/lib/active_support/inflector/methods.rb @@ -124,13 +124,13 @@ module ActiveSupport # # humanize('ssl_error') # => "SSL error" # - def humanize(lower_case_and_underscored_word, options = {}) + def humanize(lower_case_and_underscored_word, capitalize: true, keep_id_suffix: false) result = lower_case_and_underscored_word.to_s.dup inflections.humans.each { |(rule, replacement)| break if result.sub!(rule, replacement) } result.sub!(/\A_+/, "".freeze) - unless options.fetch(:keep_id_suffix, false) + unless keep_id_suffix result.sub!(/_id\z/, "".freeze) end result.tr!("_".freeze, " ".freeze) @@ -139,7 +139,7 @@ module ActiveSupport "#{inflections.acronyms[match] || match.downcase}" end - if options.fetch(:capitalize, true) + if capitalize result.sub!(/\A\w/) { |match| match.upcase } end @@ -170,8 +170,10 @@ module ActiveSupport # titleize('TheManWithoutAPast') # => "The Man Without A Past" # titleize('raiders_of_the_lost_ark') # => "Raiders Of The Lost Ark" # titleize('string_ending_with_id', keep_id_suffix: true) # => "String Ending With Id" - def titleize(word, options = {}) - humanize(underscore(word), options).gsub(/\b(?