Skip to content

Instantly share code, notes, and snippets.

@sephraim
Created February 14, 2023 23:49
Show Gist options
  • Save sephraim/c93b16dae0ba5095b4b3ddfc73ab68f5 to your computer and use it in GitHub Desktop.
Save sephraim/c93b16dae0ba5095b4b3ddfc73ab68f5 to your computer and use it in GitHub Desktop.
[Select attributes from OpenStruct]
require 'ostruct'
os = OpenStruct(foo: 1, bar: 2, baz: 3)
os.to_h.slice(:foo, :baz) #=> { foo: 1, baz: 3 }
os.to_h.values_at(:foo, :baz) #=> [1, 3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment