What governs the order of methods returned by object.public_methods( false ) ?

T

Tom Counsell

Hello

I was wondering if anyone can help me by explaining what governs the
order of methods returned by object.public_methods( false ) ?

class Test
def a
end
def b
end
def c
end
end

t = Test.new

t.public_methods( false ) # => ["a", "c", "b"]

.... so appears to be neither in the order defined, nor alphabetical and
not random either?

Thanks

Tom
 
T

ts

T> I was wondering if anyone can help me by explaining what governs the
T> order of methods returned by object.public_methods( false ) ?

methods are stored in an hash, where the key is the id of the method
name.


Guy Decoux
 
P

Phlip

Tom said:
t.public_methods( false ) # => ["a", "c", "b"]

... so appears to be neither in the order defined, nor alphabetical and
not random either?

To supplement the other answer:

def doc(anObject)
puts(anObject.class.name)

itsMethods = anObject.public_methods() -
Object.new().public_methods()

puts(itsMethods.sort()) if !itsMethods.nil?
end

I use that for a manual version of "intellisense", those annoying popups
that some editors use to tell you what to type next.
 
F

Florian Frank

I use that for a manual version of "intellisense", those annoying popups
that some editors use to tell you what to type next.

If you are using this in irb, require 'irb/completion' and hit the
<TAB> key after your method dots.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top