From: Rob Biedenharn Date: 2006-12-19T01:16:54+09:00 Subject: Re: item order in Object#methods On Dec 18, 2006, at 10:32 AM, Andrea Fazzi wrote: > Rob Biedenharn wrote: >> >> If it's important, why not sort them first: >> self.methods.sort.collect { ... } > > Because I'm interested to the methods' definition order inside the > class not to the alphabetical order of methods' name. The names > init_1, init_2, etc. were just an example. > > Andrea I'd not be surprised to hear (from someone who actually knows rather than speculates ;-) that the methods are stored in a hash and there is no definite order to them. As for the order in which they were defined, that's just the order in which they were encountered. When I run the code from your first message: rab:ruby $ ruby init_2.rb Method init_3 called! Method init_4 called! Method init_5 called! Method init_6 called! Method init_1 called! Method init_2 called! It's not even the same order as yours (although it is consistent when I run it multiple times). If the lookup is really hash-based, defining other methods could "shuffle" these around if the underlying hash table was expanded. (I'm using "hash" in its algorithmic sense, not a Ruby class.) -Rob Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com