Skip to content

Commit

Permalink
use Hash#reduce with (key, value)
Browse files Browse the repository at this point in the history
  • Loading branch information
mamantoha committed Feb 21, 2024
1 parent c468923 commit 3634c5b
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 9 deletions.
4 changes: 1 addition & 3 deletions src/crest/params_encoders/enumerated_flat_params_encoder.cr
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ module Crest
# # => [{"key1[key2]", "123"}]
# ```
def self.flatten_params(object : Hash, parent_key : String? = nil) : Array(Tuple(String, Crest::ParamsValue))
object.reduce([] of Tuple(String, Crest::ParamsValue)) do |memo, item|
k, v = item

object.reduce([] of Tuple(String, Crest::ParamsValue)) do |memo, (k, v)|
processed_key = parent_key ? "#{parent_key}[#{k}]" : k.to_s

case v
Expand Down
4 changes: 1 addition & 3 deletions src/crest/params_encoders/flat_params_encoder.cr
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ module Crest
# # => [{"key1[key2]", "123"}]
# ```
def self.flatten_params(object : Hash, parent_key : String? = nil) : Array(Tuple(String, Crest::ParamsValue))
object.reduce([] of Tuple(String, Crest::ParamsValue)) do |memo, item|
k, v = item

object.reduce([] of Tuple(String, Crest::ParamsValue)) do |memo, (k, v)|
processed_key = parent_key ? "#{parent_key}[#{k}]" : k.to_s

case v
Expand Down
4 changes: 1 addition & 3 deletions src/crest/params_encoders/nested_params_encoder.cr
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ module Crest
# # => [{"key1[key2]", "123"}]
# ```
def self.flatten_params(object : Hash, parent_key : String? = nil) : Array(Tuple(String, Crest::ParamsValue))
object.reduce([] of Tuple(String, Crest::ParamsValue)) do |memo, item|
k, v = item

object.reduce([] of Tuple(String, Crest::ParamsValue)) do |memo, (k, v)|
processed_key = parent_key ? "#{parent_key}[#{k}]" : k.to_s

case v
Expand Down

0 comments on commit 3634c5b

Please sign in to comment.