On Thu 07 Aug 2003 at 05:19:32 +0900, Harry Ohlsen wrote:

> On Thu, 7 Aug 2003 03:26, Ian Macdonald wrote:
> 
> > How does one use this with one's own objects, though?
> >
> > I just cooked up an example Person class to play with and then tried to
> > sort it as above:
> >
> > class Person
> >    include Enumerable
> >
> >    attr_accessor :first_name, :last_name, :age
> >
> >    def initialize(f,l,a)
> >      @first_name = f
> >      @last_name = l
> >      @age = a.to_i
> >    end
> >  end
> >
> > p [d, g, i, j, p, j2, j3].sort_by { |x| [x.last_name, x.first_name, x.age]
> > }
> >
> > and I get:
> >
> > ./sort_by:23: undefined method `[]' for #<Person:0x4014e37c>
> > (NoMethodError)
> 
> I would guess that there's something in the code you didn't show (ie, that 
> defines d, g, i, j, p, j2 and j3) that's causing this error message.

I assigned to the variable 'p', which is also a method in Ruby. That's
bitten me before.

Ian
-- 
Ian Macdonald               | I've already told you more than I know. 
System Administrator        | 
ian / caliban.org             | 
http://www.caliban.org      | 
                            |