Skip to content

Commit d5197d5

Browse files
committed
Use native Array#append, Array#prepend, Hash#transform_keys, and Hash#transform_keys!
Since Rails 6 requires Ruby 2.5. https://github.com/ruby/ruby/blob/ruby_2_5/NEWS Follow up #34754.
1 parent 3e50a1b commit d5197d5

File tree

11 files changed

+6
-181
lines changed

11 files changed

+6
-181
lines changed

actionpack/lib/action_controller/metal/conditional_get.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# frozen_string_literal: true
22

3-
require "active_support/core_ext/hash/keys"
4-
53
module ActionController
64
module ConditionalGet
75
extend ActiveSupport::Concern

actionpack/lib/action_controller/renderer.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# frozen_string_literal: true
22

3-
require "active_support/core_ext/hash/keys"
4-
53
module ActionController
64
# ActionController::Renderer allows you to render arbitrary templates
75
# without requirement of being in controller actions.

activejob/lib/active_job/test_helper.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# frozen_string_literal: true
22

33
require "active_support/core_ext/class/subclasses"
4-
require "active_support/core_ext/hash/keys"
54

65
module ActiveJob
76
# Provides helper methods for testing Active Job

activemodel/lib/active_model/validations.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# frozen_string_literal: true
22

33
require "active_support/core_ext/array/extract_options"
4-
require "active_support/core_ext/hash/keys"
5-
require "active_support/core_ext/hash/except"
64

75
module ActiveModel
86
# == Active \Model \Validations

activesupport/lib/active_support/core_ext/array.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@
66
require "active_support/core_ext/array/extract"
77
require "active_support/core_ext/array/extract_options"
88
require "active_support/core_ext/array/grouping"
9-
require "active_support/core_ext/array/prepend_and_append"
109
require "active_support/core_ext/array/inquiry"
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
# frozen_string_literal: true
22

3-
class Array
4-
# The human way of thinking about adding stuff to the end of a list is with append.
5-
alias_method :append, :push unless [].respond_to?(:append)
3+
require "active_support/deprecation"
64

7-
# The human way of thinking about adding stuff to the beginning of a list is with prepend.
8-
alias_method :prepend, :unshift unless [].respond_to?(:prepend)
9-
end
5+
ActiveSupport::Deprecation.warn "Ruby 2.5+ (required by Rails 6) provides Array#append and Array#prepend natively, so requiring active_support/core_ext/array/prepend_and_append is no longer necessary. Requiring it will raise LoadError in Rails 6.1."

activesupport/lib/active_support/core_ext/hash/keys.rb

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,6 @@
11
# frozen_string_literal: true
22

33
class Hash
4-
# Returns a new hash with all keys converted using the +block+ operation.
5-
#
6-
# hash = { name: 'Rob', age: '28' }
7-
#
8-
# hash.transform_keys { |key| key.to_s.upcase } # => {"NAME"=>"Rob", "AGE"=>"28"}
9-
#
10-
# If you do not provide a +block+, it will return an Enumerator
11-
# for chaining with other methods:
12-
#
13-
# hash.transform_keys.with_index { |k, i| [k, i].join } # => {"name0"=>"Rob", "age1"=>"28"}
14-
def transform_keys
15-
return enum_for(:transform_keys) { size } unless block_given?
16-
result = {}
17-
each_key do |key|
18-
result[yield(key)] = self[key]
19-
end
20-
result
21-
end unless method_defined? :transform_keys
22-
23-
# Destructively converts all keys using the +block+ operations.
24-
# Same as +transform_keys+ but modifies +self+.
25-
def transform_keys!
26-
return enum_for(:transform_keys!) { size } unless block_given?
27-
keys.each do |key|
28-
self[yield(key)] = delete(key)
29-
end
30-
self
31-
end unless method_defined? :transform_keys!
32-
334
# Returns a new hash with all keys converted to strings.
345
#
356
# hash = { name: 'Rob', age: '28' }

activesupport/lib/active_support/inflector/inflections.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# frozen_string_literal: true
22

33
require "concurrent/map"
4-
require "active_support/core_ext/array/prepend_and_append"
54
require "active_support/i18n"
65
require "active_support/deprecation"
76

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
# frozen_string_literal: true
22

33
require "abstract_unit"
4-
require "active_support/core_ext/array"
54

65
class PrependAppendTest < ActiveSupport::TestCase
7-
def test_append
8-
assert_equal [1, 2], [1].append(2)
9-
end
10-
11-
def test_prepend
12-
assert_equal [2, 1], [1].prepend(2)
6+
def test_requiring_prepend_and_append_is_deprecated
7+
assert_deprecated do
8+
require "active_support/core_ext/array/prepend_and_append"
9+
end
1310
end
1411
end

activesupport/test/core_ext/hash/transform_keys_test.rb

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)