Project

General

Profile

Actions

Bug #2496

closed

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

Added by marcandre (Marc-Andre Lafortune) about 15 years ago. Updated over 13 years ago.

Status:
Closed
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 # => #<Method : SimpleDelegator#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
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0