Skip to content

Instantly share code, notes, and snippets.

@zetachang
Created October 31, 2016 03:24
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 zetachang/fd66db4117ffbbc7e1c8c15c5acbc0f9 to your computer and use it in GitHub Desktop.
Save zetachang/fd66db4117ffbbc7e1c8c15c5acbc0f9 to your computer and use it in GitHub Desktop.
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