Project

General

Profile

Bug #2496

Delegate: #methods and #public_methods should return delegated methods too

Added by marcandre (Marc-Andre Lafortune) about 11 years ago. Updated almost 10 years ago.

Status:
Closed
Priority:
Normal
Target version:
ruby -v:
ruby 1.9.2dev (2009-12-19 trunk 26121) [x86_64-darwin10.2.0]
Backport:
[ruby-core:27224]

Description

=begin
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) =end

Also available in: Atom PDF