Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Hash#select and #reject on ruby 2.1.1 #14198

Merged
merged 4 commits into from Mar 8, 2014
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -227,6 +227,14 @@ def symbolize_keys; to_hash.symbolize_keys! end
def deep_symbolize_keys; to_hash.deep_symbolize_keys end
def to_options!; self end

def select(*args, &block)
dup.tap { |hash| hash.select!(*args, &block) }
end

def reject(*args, &block)
dup.tap { |hash| hash.reject!(*args, &block) }
end

# Convert to a regular hash with string keys.
def to_hash
_new_hash= {}
@@ -28,6 +28,14 @@ def encode_with(coder)
coder.represent_seq '!omap', map { |k,v| { k => v } }
end

def select(*args, &block)
dup.tap { |hash| hash.select!(*args, &block) }
end

def reject(*args, &block)
dup.tap { |hash| hash.reject!(*args, &block) }
end

def nested_under_indifferent_access
self
end
@@ -480,6 +480,36 @@ def test_indifferent_deleting
assert_equal hash.delete('a'), nil
end

def test_indifferent_select
hash = ActiveSupport::HashWithIndifferentAccess.new(@strings).select { |_ ,v| v == 1 }

assert_equal({ 'a' => 1 }, hash)
assert_instance_of ActiveSupport::HashWithIndifferentAccess, hash
end

def test_indifferent_select_bang
indifferent_strings = ActiveSupport::HashWithIndifferentAccess.new(@strings)
indifferent_strings.select! { |_, v| v == 1 }

assert_equal({ 'a' => 1 }, indifferent_strings)
assert_instance_of ActiveSupport::HashWithIndifferentAccess, indifferent_strings
end

def test_indifferent_reject
hash = ActiveSupport::HashWithIndifferentAccess.new(@strings).reject { |_, v| v != 1 }

assert_equal({ 'a' => 1 }, hash)
assert_instance_of ActiveSupport::HashWithIndifferentAccess, hash
end

def test_indifferent_reject_bang
indifferent_strings = ActiveSupport::HashWithIndifferentAccess.new(@strings)
indifferent_strings.reject! { |_, v| v != 1 }

assert_equal({ 'a' => 1 }, indifferent_strings)
assert_instance_of ActiveSupport::HashWithIndifferentAccess, indifferent_strings
end

def test_indifferent_to_hash
# Should convert to a Hash with String keys.
assert_equal @strings, @mixed.with_indifferent_access.to_hash
@@ -120,7 +120,9 @@ def test_find_all
end

def test_select
assert_equal @keys, @ordered_hash.select { true }.map(&:first)
new_ordered_hash = @ordered_hash.select { true }
assert_equal @keys, new_ordered_hash.map(&:first)
assert_instance_of ActiveSupport::OrderedHash, new_ordered_hash
end

def test_delete_if
@@ -143,6 +145,7 @@ def test_reject
assert_equal copy, @ordered_hash
assert !new_ordered_hash.keys.include?('pink')
assert @ordered_hash.keys.include?('pink')
assert_instance_of ActiveSupport::OrderedHash, new_ordered_hash
end

def test_clear
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.