--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 --
> 
> I'm just wondering about this:
> 
> >>RUBY_DESCRIPTION
> => "ruby 1.9.0 (2008-06-03 revision 16244) [i686-darwin9.2.2]"
> >>require 'set'
> => true
> >>s = Set.new(1..10)
> => #<Set: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}>
> >>s.map {|e| e + 10 }
> => [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
> >>s.map! {|e| e + 10 }
> => #<Set: {11, 12, 13, 14, 15, 16, 17, 18, 19, 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.
> 
> 
> David

>>s = Set.new([1,2,3,3])
=> #<Set: [1,2,3]>
>>s.map! {|i| i + 1}
=> #<Set: [2,3,4]>
>>s
=> #<Set: [2,3,4]>
>>(1..5).map {|i| i + 1}
=> [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 values 
-- no matter what the origin object -- and #map! mutates the original object, 
if possible, and returns it. #map! should return self, so it will be the same 
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
G2jzwqTgKl672CbnJnGPAXgK5
-----END PGP SIGNATURE-----

--gKMricLos+KVdGMg--