Skip to content

Instantly share code, notes, and snippets.

@trotter
Created August 6, 2009 17:27
Show Gist options
  • Select an option

  • Save trotter/163452 to your computer and use it in GitHub Desktop.

Select an option

Save trotter/163452 to your computer and use it in GitHub Desktop.
class Hash
def ref_with_destructuring(*args)
ret = args.map { |a| ref_without_destructuring(a) }
ret.size == 1 ? ret.first : ret
end
alias_method :ref_without_destructuring, :[]
alias_method :[], :ref_with_destructuring
end
# a = {:one => 1, :two => 2, :three => 3}
# b, c = a[:one, :three]
# puts b # => 1
# puts c # => 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment