From: 520079130762-0001@... (Michael Neumann) Date: 2002-11-08T06:18:37+09:00 Subject: Re: v.polar = rho, theta On Thu, 2002-11-07 at 22:09, Hans Fugal wrote: > Hi, I'm using the Vector class and needed a way to set the vector with > polar coordinates. My solution: > > class Vector > def set_polar(rho,theta) > @elements[0] = rho * Math.cos(theta) > @elements[1] = rho * Math.sin(theta) > end > end > > But it struck me that defining polar=(rho,theta) would be more > ruby-like, and I expected to call it like so: v.polar = 1, 3.14 > That doesn't work, though. This does, but it's ugly: > > irb(main):020:0> v = Vector[0,0] > Vector[0, 0] > irb(main):021:0> v.send(:polar=,1,3.14) > 0.001592652916 > irb(main):022:0> v.inspect > "Vector[-0.9999987317, 0.001592652916]" > > Is there another way, or what should I do? v.polar(1, 3.14) or v.polar= [1,3.14] # polar takes an array as argument or name the method set_polar. Regards, Michael