Last active
June 24, 2025 08:43
-
-
Save mikker/22eac630000cef4a977bef6fd7168a5d to your computer and use it in GitHub Desktop.
World's fastest mock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# usage: | |
# thing = todot(keys: { get: { turned: ["into", "reader", "methods"] } }) | |
# thing.keys.get.turned | |
# # => ["into", "reader", "methods"] | |
require "ostruct" | |
def todot(obj) | |
case obj | |
when Array | |
obj.map { todot(it) } | |
when Hash | |
OpenStruct.new(Hash[obj.map { |k, v| [k, todot(v)] }]) | |
else | |
obj | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment