Forum: Ruby about singleton_methods

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Cda3d26c2566666a0f507073b1389628?d=identicon&s=25 Kyung won Cheon (kdream95)
on 2009-01-08 08:30
class A
  class << A
    def aaa
    end

    protected
    def bbb
    end

    private
    def ccc
    end
  end
end

p A.singleton_methods # => ["aaa", "bbb"]

# private method is not a singleton method.. Why?
# Anyway 'ccc' is defined in a singleton class of A ?

###############
# Help Me^^
###############
703fbc991fd63e0e1db54dca9ea31b53?d=identicon&s=25 Robert Dober (Guest)
on 2009-01-08 10:06
(Received via mailing list)
On Thu, Jan 8, 2009 at 8:29 AM, Kyung won Cheon <kdream95@gmerce.co.kr>
wrote:
>    def ccc
> # Help Me^^
> ###############
> --
> Posted via http://www.ruby-forum.com/.
>
>
I have never noticed that before, I certainly do not like that.

If you need that information you could do the following

class Object
  def my_sing_methods # this does not sing
    singleton_methods + begin
   class << self; self end.private_instance_methods( false )
      rescue
        [ ]
    end
  end
end

This however gives you three more methods, namely :inherited,
:initialize, :initialize_copy.
You can of course get rid of them, but what if they are overloaded?
Unfortunately I can not
think of any simple code to cover that.

Cheers
Robert
This topic is locked and can not be replied to.