Permalink
Browse files

Use method_defined? instead of responds_to?

  • Loading branch information...
1 parent 47d599c commit 0153347feab456398f03d5564840eeea974ea3c4 @sferik committed Jul 7, 2012
Showing with 3 additions and 3 deletions.
  1. +2 −2 lib/twitter/core_ext/hash.rb
  2. +1 −1 lib/twitter/core_ext/kernel.rb
@@ -6,7 +6,7 @@ class Hash
# @return [Hash]
def except(*keys)
self.dup.except!(*keys)
- end unless respond_to?(:except)
+ end unless method_defined?(:except)
# Replaces the hash without the given keys.
#
@@ -15,7 +15,7 @@ def except(*keys)
def except!(*keys)
keys.each{|key| delete(key)}
self
- end unless respond_to?(:except!)
+ end unless method_defined?(:except!)
# Take a list and merge it into the hash with the correct key
#
@@ -1,7 +1,7 @@
module Kernel
# Returns the object's singleton class (exists in Ruby 1.9.2)
- def singleton_class; class << self; self; end; end unless respond_to?(:singleton_class)
+ def singleton_class; class << self; self; end; end unless method_defined?(:singleton_class)
# class_eval on an object acts like singleton_class.class_eval.
def class_eval(*args, &block)

1 comment on commit 0153347

@erebor
Collaborator
erebor commented on 0153347 Jul 7, 2012

Looks OK to me. Though I had to go look up the difference between respond_to? and method_defined? in a module. Learn something new every day!

Please sign in to comment.