From: Farrel Lifson Date: 2006-03-10T01:20:07+09:00 Subject: Re: nuby question: sorting with nils I don't think you can access the attributes of a Struct from inside it using object variables (like @a). C:\Documents and Settings\flifson\Desktop>irb irb(main):001:0> X = Struct.new :a,:b => X irb(main):002:0> class X irb(main):003:1> def print_attributes irb(main):004:2> puts "#{@a}:#{b}" irb(main):005:2> end irb(main):006:1> end => nil irb(main):007:0> s = X.new 'hello','world' => # irb(main):008:0> s.print_attributes :world Notice only the value of the b attribute was printed ('world'). That's because self. was implicitly added to the front of it, so it became self.b which will return the correct value. Changing it to: def <=> other if not a 1 elsif not b -1 else if a == other.a b <=> other.b else a <=> other.a end end end produces: C:\Documents and Settings\flifson>ruby settest.rb #, #, #, #}> -1 1 0 My guess is that the Struct is really a type of Hash and that it uses the method_missing system hook to actually retrieve the data from whatever it uses to store the data. It has a lot of Hash like methods such as values, each_pair etc etc. Farrel