Skip to content

Commit

Permalink
Replace OpenStruct with Struct
Browse files Browse the repository at this point in the history
  • Loading branch information
javierjulio committed Apr 15, 2024
1 parent 7031210 commit 468ac62
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions lib/utils/hash_extension.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
module CoreExtensions
refine Hash do
def to_struct
OpenStruct.new(self.each_with_object({}) do |(key, val), acc|
acc[key] = val.is_a?(Hash) ? val.to_struct : val
end)
Struct.new(*self.keys).new(*self.values.map { |value| value.is_a?(Hash) ? value.to_struct : value })
end
end
end

0 comments on commit 468ac62

Please sign in to comment.