Skip to content

Instantly share code, notes, and snippets.

@bcardiff
Created October 23, 2017 23:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bcardiff/b6c8fff62a5812e476a57e90c21a51c2 to your computer and use it in GitHub Desktop.
Save bcardiff/b6c8fff62a5812e476a57e90c21a51c2 to your computer and use it in GitHub Desktop.
struct NamedTuple
macro map_keys(tuple, properties)
{% begin %}
%tuple = {{tuple}}
NamedTuple.new(
{% for key, value in properties %}
{{value.id}}: %tuple[{{key.symbolize}}],
{% end %}
)
{% end %}
end
end
NamedTuple.map_keys({a: 1, b: "foo"}, {a: :qux, b: :bar}) # => {qux: 1, bar: "foo"} : NamedTuple(qux: Int32, bar: String)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment