From: Matthew Boeh Date: 2007-11-11T19:18:12+09:00 Subject: Re: method names in 1.9 --tNQTSEo8WG/FKZ8E Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Nov 11, 2007 at 06:09:21PM +0900, Trans wrote: >=20 [snip]=20 > > - to_splat > > > > Unlike invoke_method above, you didn't provide your sought name. It > > must be a clear name to be use for splat. Any opinion? > > Regarding 'to_xxx', we have 'to_open' added in 1.9 that must be > > irritate you. It is used to implement open on anything other than > > strings. >=20 > I tend to agree with David here. For instance, I once had > Integer#to_roman, but depraecated it in favor to Integer#roman. Why is > the preposition needed? #splat seems fine. On the other hand one could > just argue that a "splat" is a form of Array, so #to_splat is just an > odd named part of the to_a and to_ary "family" of methods. Would > #to_args make us feel any better? >=20 > T. >=20 >=20 I have a few thoughts here. 1. The splat, although I love it dearly, is a generally nonintuitive concep= t. =20 Considering how ludicrous #to_list_of_arguments would be, it becomes necess= ary=20 to choose some sort of memorable term for the concept. I think "splat" is s= uch=20 a term -- the asterisk looks like something that's been splattered, the=20 process of separating the elements of an array into arguments of a function= is=20 consistent with the term "splatter," and it's an active-sounding and unique= =20 term for an unusual operation. 2. That said, I can't think of a valid use case for implementing #to_splat= =20 separately from #to_a that isn't tantamount to direct hostility against any= one=20 who has the pleasure to read your code. Many Ruby programmers would be=20 genuinely confused by a use of the splat on something that isn't an array, = and =20 the majority of the remainder would likely expect the semantics to be=20 identical to #to_a. 3. Finally, I have to admit to surprise for why the asterisk isn't consider= ed=20 a unary operator and treated as such. That is: class Confusing def to_a [1,2,3] end =20 def *@ # that is, analogous to -@, +@ to_a.reverse end end If I were to unexpectedly come across code like this: func(*ary) without any understanding of the splat, I'd probably look first for an=20 implementation of the unary asterisk as an operator. def *@ looks like line= =20 noise, sure, but not significantly more so than -@, +@, etc. -- Matthew Boeh --tNQTSEo8WG/FKZ8E 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) iD8DBQFHNtbnfi+i1R7d/ZwRAuqDAKCEQTmTDpyP9w0a6WdRaHmxSvncfwCgn7KH bvbEYPgOKxuXnjdbfD5ZCRY= =SL7y -----END PGP SIGNATURE----- --tNQTSEo8WG/FKZ8E--