From: Paul Mckibbin Date: 2008-03-11T08:43:29+09:00 Subject: Re: Which is better -- method option or multiple methods? Lionel Bouton wrote: > Trans wrote: >> In the case of limited options, like the following example, which is >> better? > If the direction is supposed to be static everywhere in the code, I'd > use the align_(*args) methods. > > But if the direction is dynamic (based on a property, a preference, any > algorithm, ...) then I'd use the align(direction, *args) method. > Otherwise you will get > > case direction > when :left > align_left(...) > when :right > align_right(...) > when :center > align_center(...) > end > > constructs everywhere... > > But I'd probably use the align_* methods to implement align(direction, > ...) for readability and flexibility anyway. In this case align_* would > be private if you don't need them to simplify the API or public if you > actually need them. > > Lionel Surely then there would then be a decision making process that would set the variable , and how is that simpler than calling the function? In any case, you can replace your "case direction" constructs with send("align_#{direction}",spacing) Mac -- Posted via http://www.ruby-forum.com/.