Skip to content

Commit 583937f

Browse files
committed
Merge pull request #1128 from marshall-lee/use_each_with_object
Use each_with_object instead of inject.
2 parents 079b2aa + ce5c310 commit 583937f

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

lib/grape/dsl/inside_route.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def declared(params, options = {}, declared_params = nil)
2828
declared(param || {}, options, declared_params)
2929
end
3030
else
31-
declared_params.inject(Hashie::Mash.new) do |hash, key|
31+
declared_params.each_with_object(Hashie::Mash.new) do |key, hash|
3232
key = { key => nil } unless key.is_a? Hash
3333

3434
key.each_pair do |parent, children|
@@ -43,8 +43,6 @@ def declared(params, options = {}, declared_params = nil)
4343
params[parent]
4444
end
4545
end
46-
47-
hash
4846
end
4947
end
5048
end

lib/grape/formatter/serializable_hash.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ def serialize(object)
2121
elsif object.is_a?(Array) && !object.map { |o| o.respond_to? :serializable_hash }.include?(false)
2222
object.map(&:serializable_hash)
2323
elsif object.is_a?(Hash)
24-
object.inject({}) do |h, (k, v)|
24+
object.each_with_object({}) do |(k, v), h|
2525
h[k] = serialize(v)
26-
h
2726
end
2827
else
2928
object

0 commit comments

Comments
 (0)