Updated to latest will_paginate
[gitorious:dgiuntas-clone.git] / vendor / plugins / will_paginate / lib / will_paginate / core_ext.rb
1 require 'set'
2 require 'will_paginate/array'
3
4 unless Hash.instance_methods.include? 'except'
5   Hash.class_eval do
6     # Returns a new hash without the given keys.
7     def except(*keys)
8       rejected = Set.new(respond_to?(:convert_key) ? keys.map { |key| convert_key(key) } : keys)
9       reject { |key,| rejected.include?(key) }
10     end
11  
12     # Replaces the hash without only the given keys.
13     def except!(*keys)
14       replace(except(*keys))
15     end
16   end
17 end
18
19 unless Hash.instance_methods.include? 'slice'
20   Hash.class_eval do
21     # Returns a new hash with only the given keys.
22     def slice(*keys)
23       allowed = Set.new(respond_to?(:convert_key) ? keys.map { |key| convert_key(key) } : keys)
24       reject { |key,| !allowed.include?(key) }
25     end
26
27     # Replaces the hash with only the given keys.
28     def slice!(*keys)
29       replace(slice(*keys))
30     end
31   end
32 end