Skip to content

Commit

Permalink
Use Hash#each_key instead of Hash#keys.each
Browse files Browse the repository at this point in the history
Hash#keys.each allocates an array of keys.

Hash#each_key iterates through the keys without allocating a
new array and as such is a better, more specific tool for the
job.
  • Loading branch information
jonatack committed Dec 1, 2014
1 parent e2fcff3 commit ee571fe
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ransack/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def sanitized_scope_args(args)
end

def collapse_multiparameter_attributes!(attrs)
attrs.keys.each do |k|
attrs.each_key do |k|
if k.include?(Constants::LEFT_PARENTHESIS)
real_attribute, position = k.split(/\(|\)/)
cast =
Expand Down

1 comment on commit ee571fe

@jonatack
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hash#each_key arrived with Ruby 1.9, but Rails itself dropped support for Ruby 1.8 and the upcoming Rails 5 scheduled for next summer will target Ruby 2.2 and up only. In short, anyone still using Ruby 1.8 will need to use an earlier Ransack release than the upcoming Ransack 1.6.0.

Please sign in to comment.