aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext
diff options
context:
space:
mode:
authorGabriel Sobrinho <gabriel.sobrinho@gmail.com>2019-03-06 11:16:07 -0300
committerGabriel Sobrinho <gabriel.sobrinho@gmail.com>2019-03-06 13:34:04 -0300
commit87468284d523d5e760445633666232840777e312 (patch)
tree260ad601d42222edc9e715056ac44f5e6a42fefa /activesupport/lib/active_support/core_ext
parentb366be3b5b28f01c8a55d67a5161ec36f53d555c (diff)
downloadrails-87468284d523d5e760445633666232840777e312.tar.gz
rails-87468284d523d5e760445633666232840777e312.tar.bz2
rails-87468284d523d5e760445633666232840777e312.zip
Fix including/excluding flattening
Diffstat (limited to 'activesupport/lib/active_support/core_ext')
-rw-r--r--activesupport/lib/active_support/core_ext/array/access.rb12
-rw-r--r--activesupport/lib/active_support/core_ext/enumerable.rb2
2 files changed, 7 insertions, 7 deletions
diff --git a/activesupport/lib/active_support/core_ext/array/access.rb b/activesupport/lib/active_support/core_ext/array/access.rb
index c9eecc55f9..10e4c6b09d 100644
--- a/activesupport/lib/active_support/core_ext/array/access.rb
+++ b/activesupport/lib/active_support/core_ext/array/access.rb
@@ -31,21 +31,21 @@ class Array
# Returns a new array that includes the passed elements.
#
- # Example: [ 1, 2, 3 ].including(4, 5) => [ 1, 2, 3, 4, 5 ]
+ # [ 1, 2, 3 ].including(4, 5) => [ 1, 2, 3, 4, 5 ]
+ # [ [ 0, 1 ] ].including([ [ 1, 0 ] ]) => [ [ 0, 1 ], [ 1, 0 ] ]
def including(*elements)
- self + elements.flatten
+ self + elements.flatten(1)
end
# Returns a copy of the Array excluding the specified elements.
#
- # people = ["David", "Rafael", "Aaron", "Todd"]
- # people.excluding "Aaron", "Todd"
- # # => ["David", "Rafael"]
+ # ["David", "Rafael", "Aaron", "Todd"].excluding("Aaron", "Todd") => ["David", "Rafael"]
+ # [ [ 0, 1 ], [ 1, 0 ] ].excluding([ [ 1, 0 ] ]) => [ [ 0, 1 ] ]
#
# Note: This is an optimization of <tt>Enumerable#excluding</tt> that uses <tt>Array#-</tt>
# instead of <tt>Array#reject</tt> for performance reasons.
def excluding(*elements)
- self - elements.flatten
+ self - elements.flatten(1)
end
# Alias for #excluding.
diff --git a/activesupport/lib/active_support/core_ext/enumerable.rb b/activesupport/lib/active_support/core_ext/enumerable.rb
index d6fb89e588..4675c41936 100644
--- a/activesupport/lib/active_support/core_ext/enumerable.rb
+++ b/activesupport/lib/active_support/core_ext/enumerable.rb
@@ -125,7 +125,7 @@ module Enumerable
# {foo: 1, bar: 2, baz: 3}.excluding :bar
# # => {foo: 1, baz: 3}
def excluding(*elements)
- elements.flatten!
+ elements.flatten!(1)
reject { |element| elements.include?(element) }
end