trotter (owner)

Revisions

gist: 163452 Download_button fork
public
Public Clone URL: git://gist.github.com/163452.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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