From: Julian Leviston Date: 2009-02-03T15:48:14+09:00 Subject: Re: choose parameter to solve for What do you mean? Blog: http://random8.zenunit.com/ Learn rails: http://sensei.zenunit.com/ On 03/02/2009, at 5:10 PM, Jason Lillywhite wrote: > I'm looking for a clean way to write a function that allows me to > choose > which parameter to solve for assuming all others are known. Is it good > design to do something like this: ? > > class Foo > def initialize(x, y, z) > @x, @y, @z = x, y, z > end > > def function(var) > if @x.nil? > @x = var > elsif @y.nil? > @y = var > else > @z = var > end > @x + @y + @z > end > > end > > z = Foo.new(1, 2, nil) > z.function(3) > => 6 > ?? > -- > Posted via http://www.ruby-forum.com/. >