Skip to content

Instantly share code, notes, and snippets.

@oieioi
Created July 20, 2022 13:44
Show Gist options
  • Save oieioi/99317db346e14ad01443d44cac325c54 to your computer and use it in GitHub Desktop.
Save oieioi/99317db346e14ad01443d44cac325c54 to your computer and use it in GitHub Desktop.
class Hash
def to_struct
klass = Struct.new(*keys.map(&:to_sym).uniq, keyword_init: true)
klass.new(self)
end
end
pp({ :keys => 'arienai', 'keys' => 'unko'}.to_struct)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment