From: Lyndon Samson Date: 2005-11-23T07:27:35+09:00 Subject: Re: what is the ruby way to do this? ------=_Part_17900_9817640.1132698449982 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline $hash =3D {} def add(key, val) if $hash.has_key?(key) if $hash[key].is_a?(Array) $hash[key] << val else $hash[key] =3D [$hash[key], val] end else $hash[key] =3D val end end def add2(key, val) if $hash.has_key?(key) $hash[key].to_a << val else $hash[key] =3D val.to_a end end key =3D "a" val =3D "aval" add2(key, val) puts $hash.inspect key =3D "a" val =3D "aval2" add2(key, val) puts $hash.inspect ------=_Part_17900_9817640.1132698449982--