Skip to content

Instantly share code, notes, and snippets.

@zetachang
Created October 31, 2016 03:24
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
class Hash
def destruct(&block)
keys = block.parameters.map{|a| a[1]}
block.call(*self.values_at(*keys))
end
end
h = { a: 10, foo: 'bar', c: true }
h.destruct { |foo, a|
puts "foo: #{foo} a: #{a}"
# => foo: bar a: 10
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment