Browse files

use `method_defined?` in core_ext

  • Loading branch information...
1 parent f4f2d41 commit 447817565a50e10dc3166def32f38f69fbee0a19 @mislav committed Jul 26, 2011
Showing with 5 additions and 16 deletions.
  1. +5 −16 lib/will_paginate/core_ext.rb
View
21 lib/will_paginate/core_ext.rb
@@ -1,20 +1,9 @@
require 'set'
require 'will_paginate/array'
-# helper to check for method existance in ruby 1.8- and 1.9-compatible way
-# because `methods`, `instance_methods` and others return strings in 1.8 and symbols in 1.9
-#
-# ['foo', 'bar'].include_method?(:foo) # => true
-class Array
- def include_method?(name)
- name = name.to_sym
- !!(find { |item| item.to_sym == name })
- end
-end
-
-## everything below copied from ActiveSupport so we don't depend on it ##
+# copied from ActiveSupport so we don't depend on it
-unless Hash.instance_methods.include_method? :except
+unless Hash.method_defined? :except
Hash.class_eval do
# Returns a new hash without the given keys.
def except(*keys)
@@ -29,7 +18,7 @@ def except!(*keys)
end
end
-unless Hash.instance_methods.include_method? :slice
+unless Hash.method_defined? :slice
Hash.class_eval do
# Returns a new hash with only the given keys.
def slice(*keys)
@@ -44,7 +33,7 @@ def slice!(*keys)
end
end
-unless String.instance_methods.include_method? :constantize
+unless String.method_defined? :constantize
String.class_eval do
def constantize
unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ self
@@ -56,7 +45,7 @@ def constantize
end
end
-unless String.instance_methods.include_method? :underscore
+unless String.method_defined? :underscore
String.class_eval do
def underscore
self.to_s.gsub(/::/, '/').

0 comments on commit 4478175

Please sign in to comment.