diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2018-10-02 11:05:40 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-02 11:05:40 -0400 |
commit | cf608ee34dd833b0357ef4eefa692db33242d2aa (patch) | |
tree | 7515c745a15dd29e2e50aca534f764044bece91c /activesupport/lib | |
parent | 96e69b5a33f44e5339345ef3c4871aba51a1e938 (diff) | |
parent | ec9a89cb8be037cde2466a5347ea5c4ec648a4c3 (diff) | |
download | rails-cf608ee34dd833b0357ef4eefa692db33242d2aa.tar.gz rails-cf608ee34dd833b0357ef4eefa692db33242d2aa.tar.bz2 rails-cf608ee34dd833b0357ef4eefa692db33242d2aa.zip |
Merge pull request #33058 from gmcgibbon/string_first_last_negative_deprecation
Add deprecation warning when String#first and String#last receive neg…
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/core_ext/string/access.rb | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/string/access.rb b/activesupport/lib/active_support/core_ext/string/access.rb index 58591bbaaf..4ca24028b0 100644 --- a/activesupport/lib/active_support/core_ext/string/access.rb +++ b/activesupport/lib/active_support/core_ext/string/access.rb @@ -75,6 +75,10 @@ class String # str.first(0) # => "" # str.first(6) # => "hello" def first(limit = 1) + ActiveSupport::Deprecation.warn( + "Calling String#first with a negative integer limit " \ + "will raise an ArgumentError in Rails 6.1." + ) if limit < 0 if limit == 0 "" elsif limit >= size @@ -95,6 +99,10 @@ class String # str.last(0) # => "" # str.last(6) # => "hello" def last(limit = 1) + ActiveSupport::Deprecation.warn( + "Calling String#last with a negative integer limit " \ + "will raise an ArgumentError in Rails 6.1." + ) if limit < 0 if limit == 0 "" elsif limit >= size |