From: Suhku Huh Date: 2006-03-11T06:59:12+09:00 Subject: Question about Hash's initialize ------=_Part_13862_3707242.1142027936355 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline I'd like to make a class that behave like a Hash but keeps keys in created order. Followings are some initial testing codes... class OHash < Hash def self.[](*args) if (args.size =3D=3D 1) and args[0].kind_of?(Hash) args[0].each_key { |k| puts k} else args.each_index { |i| puts(a[i]) if (i % 2) =3D=3D 0 } end super end def []=3D(key, value) puts key super end end I'm going to replace puts call to assignment later, and would like to use instead of Hash or even override default Hash's methods using alias. Tests... > OHash['b'=3D>2, 'c'=3D>3, 'a'=3D>1, 'aa'=3D>11] aa a b c =3D> {'aa'=3D>11, 'a'=3D>1, 'b'=3D>2, 'c'=3D>3} > OHash['b', 2, 'c', 3, 'a', 1, 'aa', 11] b c a aa As the code says, argument to class [] method is a already Hash when we initialize hash form. Any comments, ideas and test results would be appreciated. Suhku ------=_Part_13862_3707242.1142027936355--