--gKMricLos+KVdGMg
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Tue, Jun 03, 2008 at 10:13:07AM +0900, David A. Black wrote:
> Hi --
>=20
> I'm just wondering about this:
>=20
> >>RUBY_DESCRIPTION
> =3D> "ruby 1.9.0 (2008-06-03 revision 16244) [i686-darwin9.2.2]"
> >>require 'set'
> =3D> true
> >>s =3D Set.new(1..10)
> =3D> #<Set: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}>
> >>s.map {|e| e + 10 }
> =3D> [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
> >>s.map! {|e| e + 10 }
> =3D> #<Set: {11, 12, 13, 14, 15, 16, 17, 18, 19, 20}>
>=20
> I'm just wondering whether it would make more sense for Set to have a
> #map method that returned a set, rather than an array, as long as that
> behavior is considered meaningful (as it appears to be since that's
> how Set#map! is working). Otherwise that aspect of the map/map!
> distinction seems kind of arbitrary.
>=20
>=20
> David

>>s =3D Set.new([1,2,3,3])
=3D> #<Set: [1,2,3]>
>>s.map! {|i| i + 1}
=3D> #<Set: [2,3,4]>
>>s
=3D> #<Set: [2,3,4]>
>>(1..5).map {|i| i + 1}
=3D> [2, 3, 4, 5, 6]
>>(1..5).map! {|i| i + 1}
(NoMethodError)

It seems consistent to me that #map returns an array of the collected value=
s=20
-- no matter what the origin object -- and #map! mutates the original objec=
t,=20
if possible, and returns it. #map! should return self, so it will be the sa=
me=20
class as the original.

--
Matthew Boeh

--gKMricLos+KVdGMg
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFIRNWPfi+i1R7d/ZwRAi0iAJ9TMnKYkdV8l1hildz+Y0LF2ANVygCgwX3Y
G2jzwqTgKl672CbnJnGPAXg=
=rvK5
-----END PGP SIGNATURE-----

--gKMricLos+KVdGMg--