From: ptkwt@...1.aracnet.com (Phil Tomson) Date: 2002-11-23T03:58:35+09:00 Subject: Re: Allow *array expansion anywhere in list In article <20021122163518.GA9460@pelikan>, Carlos wrote: >> |The findings of fact (well, OK, my opinion) are these: >> | >> |*array is only allowed at the end of arrays because it's implemented >as a hack. >> >> This is a false assumption. The reason is it's not encouraged. If >> you need array expansion in the middle of arguments, there must be >> something wrong, perhaps in method argument design. > >Yes, but sometimes you don't design the method, and expansion is useful to >encapsulate arguments. For example, this is what I tried to do some weeks >ago, and seemed very natural: > >== >class Point > attr_accessor :x, :y > > def initialize x=0,y=0 > @x=x; @y=y > end > > def to_a > [@x, @y] > end >end > >p1=Point.new(5,4) >p2=Point.new(10,10) > ># now I have a 'line' method, from an external library, defined as: ># def line x1, y1, x2, y2, attrs > >line(*p1, *p2, attrs) # parse error >== > >Isn't this more clear and natural and mantainable and easy than > >line(p1.x, p1.y, p2.x, p2.y, attrs) > >? Ummmm... I'd have to answer no. Is the external library written in Ruby? If so, then it would be better to do add another method: line_from_points(p1,p2,attrs) Phil