Skip to content

Instantly share code, notes, and snippets.

@mikker
Last active June 24, 2025 08:43
Show Gist options
  • Save mikker/22eac630000cef4a977bef6fd7168a5d to your computer and use it in GitHub Desktop.
Save mikker/22eac630000cef4a977bef6fd7168a5d to your computer and use it in GitHub Desktop.
World's fastest mock
# 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