diff options
| author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2017-03-28 18:02:00 -0400 | 
|---|---|---|
| committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2017-03-28 18:02:00 -0400 | 
| commit | d046390c324142afffbf105075a1f4998c149c14 (patch) | |
| tree | 80f810b406caa902e68bb9f1630bac2b61c0e0cb | |
| parent | 0875256fe97d919d072d09f4114749fc9266f236 (diff) | |
| download | rails-d046390c324142afffbf105075a1f4998c149c14.tar.gz rails-d046390c324142afffbf105075a1f4998c149c14.tar.bz2 rails-d046390c324142afffbf105075a1f4998c149c14.zip  | |
Use keyword arguments instead of hash
| -rw-r--r-- | activesupport/lib/active_support/core_ext/string/inflections.rb | 8 | ||||
| -rw-r--r-- | activesupport/lib/active_support/inflector/methods.rb | 12 | 
2 files changed, 11 insertions, 9 deletions
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(?<!\w['’`])[a-z]/) { |match| match.capitalize } +    def titleize(word, keep_id_suffix: false) +      humanize(underscore(word), keep_id_suffix: keep_id_suffix).gsub(/\b(?<!\w['’`])[a-z]/) do |match| +        match.capitalize +      end      end      # Creates the name of a table like Rails does for models to table names.  | 
