From: Rick DeNatale Date: 2006-10-10T22:36:44+09:00 Subject: Re: [ruby-cvs:18323] ruby: * eval.c (splat_value): use "to_splat" instead of "to_ary" to On 10/10/06, Yukihiro Matsumoto wrote: > Hi, > > In message "Re: [ruby-cvs:18323] ruby: * eval.c (splat_value): use "to_splat" instead of "to_ary" to" > on Tue, 10 Oct 2006 10:47:43 +0900, dblack@wobblini.net writes: > |The possible problem with to_values is that it suggests that what was > |there before the conversion was *not* values, which I think might be > |misleading. to_args still seems too specific to me -- for example, in > |this: > | > | [*0...10] > | > |there's nothing arg-related about what's happening to the range. > > It was *a value* before conversion. Yes, but the proposal is not to_value but to_values which might be subtle but is a crucial distinction. > |I also have a question about the use of this method. Do you think it > |would always be defined in terms of the * itself? In other words: > | > | class C > | def initialize(a) > | @array = a > | end > | def to_values > | *a > | end > | end > | > |But then wouldn't it just return an array? Or would the * still > |un-array it? > | > | c = C.new([1,2,3,4]) > | Hash[*c] # == Hash[1,2,3,4] ? > | > |But then... why have a separate definition? I'm sure there's a reason > |-- I'm just not yet seeing how one would use it. > > I am not sure I understand you here. Here's little bit modified your > example. > > class C > def initialize(a) > @array = a > end > def to_values > @array > end > end > > c = C.new([1,2,3,4]) > Hash[*c] # == Hash[1,2,3,4] > > Do you see any problem? I'm not sure that I do. You seem to be saying that some might find that that last line: Hash[*c] produces {1 => 2, 3 =>4} But to my mind this is being overprotective at the cost of being restrictive. Putting that * in the code indicates that the programmer WANTS the conversion to be applied. As I've said before, the changes being made in 1.9 in this area just don't feel right to me, but that's just my opinion. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/