From: Marc-Andre Lafortune Date: 2009-12-19T10:39:06+09:00 Subject: [ruby-core:27224] [Bug #2496] Delegate: #methods and #public_methods should return delegated methods too Bug #2496: Delegate: #methods and #public_methods should return delegated methods too http://redmine.ruby-lang.org/issues/show/2496 Author: Marc-Andre Lafortune Status: Open, Priority: Normal Category: lib, Target version: 1.9.2 ruby -v: ruby 1.9.2dev (2009-12-19 trunk 26121) [x86_64-darwin10.2.0] require 'delegate' s = SimpleDelegator.new "Hello, world!" s.respond_to? :upcase # => true s.method :upcase # => # s.methods.include? :upcase # => false, true expected Similar problem with public_methods. I propose that they return the union of methods from the delegator object and the methods of the object delegated to (only the public ones, since other ones are not forwarded) Patch: diff --git a/lib/delegate.rb b/lib/delegate.rb index 77804e4..2fd5b49 100644 --- a/lib/delegate.rb +++ b/lib/delegate.rb @@ -158,6 +158,22 @@ class Delegator end # + # Returns the methods available to this delegate object as the union + # of this object's methods and the public methods of \_\_getobj\_\_. + # + def methods + self.__getobj__.public_methods | super + end + + # + # Returns the methods available to this delegate object as the union of this object + # and the methods of \_\_getobj\_\_. + # + def public_methods(all=true) + self.__getobj__.public_methods(all) | super + end + + # # Returns true if two objects are considered same. # def ==(obj) ---------------------------------------- http://redmine.ruby-lang.org