From: Martin DeMello Date: 2004-06-14T14:48:38+09:00 Subject: Re: [RCR]: Replace pack and unpack with OO versions Bill Atkins wrote: > Rather than having code like this: > > flags, ignore, length, name = data.unpack "nnna*" > > let's try this: > > u = Unpacker.new data > flags, ignore, length, name = u.word, u.word, u.word, u.string > > I think this looks a lot neater and is much more maintainable. A > similar thing could be done with pack. Alternatively, something I've been thinking of is to let pack and unpack take array arguments, which are 'compiled' into pack/unpack strings. e.g. flags, ignore, length, name = u.unpack [:word, :word, :word, :string] All the compiler would have to do is translate symbols, and pass numbers through unchanged. Or, if you wanted to construct it in terms of pairs like [[:string, 3]], just run a flatten first. martin