Quoteing dblack / wobblini.net, on Mon, Nov 15, 2004 at 09:00:18AM +0900: > > I'd like to mix a little bit more of Array into Struct! > > You can do that (just write a module and extend your Structs), though > in general I think Structs are more hash-like than array-like. If > there's a #[] method, I wouldn't expect it to be restricted to > integers. (Is the order of #to_a for Structs even guaranteed?) Aha, so I expected it be more like an Array, and you expected it to be more like a Hash! But, it is not quite either. :-) You can index by symbols (hash-like), or by integer (array-like). Pickaxe has examples of using integer indexes that rely on the ordering, for both #[] and #to_a, so I'm assuming it's intended to be guaranteed. From ri1.8: Returns the values for this instance as an array. Customer = Struct.new(:name, :address, :zip) joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345) joe.to_a[1] #=> "123 Maple, Anytown NC" > (Tangential question: > > How does one refer to the methods one defines on a Struct, or for that > matter its other instance methods? The usual ClassName#method_name > thing doesn't work :-) The thing Struct.new returns is enough of a class, isn't it? irb(main):001:0> s = Struct.new('MyClass', :foo, :bar) => Struct::MyClass irb(main):002:0> s.methods => ["send", "name", "display", "class_eval", "object_id", ... Cheers, Sam