Skip to content
Newer
Older
100644 31 lines (26 sloc) 737 Bytes
1479cb2 - Factor Hash monkey patching into core_ext/hash.rb
chris authored Jul 13, 2007
1 require 'set'
2
4478175 @mislav use `method_defined?` in core_ext
authored Jul 26, 2011
3 # copied from ActiveSupport so we don't depend on it
c71ca99 @mislav fix spec for will_paginate in ViewHelpers::Common
authored May 9, 2008
4
4478175 @mislav use `method_defined?` in core_ext
authored Jul 26, 2011
5 unless Hash.method_defined? :except
1479cb2 - Factor Hash monkey patching into core_ext/hash.rb
chris authored Jul 13, 2007
6 Hash.class_eval do
7 # Returns a new hash without the given keys.
8 def except(*keys)
9 rejected = Set.new(respond_to?(:convert_key) ? keys.map { |key| convert_key(key) } : keys)
10 reject { |key,| rejected.include?(key) }
11 end
12
13 # Replaces the hash without only the given keys.
14 def except!(*keys)
15 replace(except(*keys))
16 end
17 end
18 end
19
4478175 @mislav use `method_defined?` in core_ext
authored Jul 26, 2011
20 unless String.method_defined? :underscore
ad66001 @mislav specs for common view helpers
authored May 9, 2008
21 String.class_eval do
22 def underscore
23 self.to_s.gsub(/::/, '/').
24 gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
25 gsub(/([a-z\d])([A-Z])/,'\1_\2').
26 tr("-", "_").
27 downcase
28 end
29 end
30 end
Something went wrong with that request. Please try again.