From: Robert Klemme Date: 2010-01-26T17:15:15+09:00 Subject: Re: how to refactor these code? 2010/1/26 Zhenning Guan : > def ss(s = 'hello', yeah = nil) >  if yeah >    puts "something" >  else >    puts "other thing" >  end > >  #code continue .... > end What do you need argument "s" for? > I have this method, use it like that: > > ss('hi', yeah = true) > ss('hello') > ss('fuck', yeah = true) > ss('hello',yeah = true) > > very ugly.. sometimes I just need to passed yeah = true, but I have to > added 'hello' first. > > what should I do? Define two methods. At least from the interface this is cleaner. Generally flags that control method behavior are considered bad practice because they tend to make the implementation of a method more complex and tie things together that might really be independent (just consider what happens if you inherit a class and want to change only one of the two variants). Note, you can still share an internal implementation under the hood e.g. def ss1 ss_impl "something" end def ss2 ss_impl "other thing" end private def ss_impl(x) ... end But your example is really a bit short to come up with a definitive answer how to improve this. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/