aboutsummaryrefslogtreecommitdiffstats
path: root/spec/doubles/hash.rb
blob: fd9edd34adfb163d0cae0a1953fac0ed986c15fc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Hash
  def ordered_array
    to_a.sort { |(key1, value1), (key2, value2)| key1.hash <=> key2.hash }
  end

  undef :keys
  def keys
    ordered_array.collect(&:first)
  end

  undef :values
  def values
    ordered_array.collect { |_, v| v }
  end

  undef :each
  def each(&block)
    ordered_array.each(&block)
  end

  undef :shift
  def shift
    returning to_a.first do |k, v|
      delete(k)
    end
  end
end