I have three methods that are really similar but do slightly different things. This doesn't feel very DRY to me, but I can't think of a way to reduce the duplication. Here are the methods, I think they're fairly self explanatory:# Present a date as a string, optionally without a year# Example output: December 1, 2011def date_string(year=true)  if date    str = %B %e    str += , %Y if year    date.strftime(str).gsub('  ',' ')  else      endend# Present a time as a string, optionally with a meridian (am/pm)# Example output: 1:30 PMdef start_time_string(meridian=true)  if start_time    str = %l:%M    str +=  %p if meridian    start_time.strftime(str).lstrip  else      endend# Present a time as a string, optionally with a meridian (am/pm)# Example Output: 2:00def end_time_string(meridian=true)  if end_time    str = %l:%M    str +=  %p if meridian    end_time.strftime(str).lstrip  else      endendEach method just presents a time as a string with certain options, and if the time object they're trying to present is nil, they return an empty string.Any ideas how to DRY this up?
Presenting a time as a string
strings;ruby;datetime
To complement @mjgpy3's answer, some notes:def date_string(year=true). That's idiomatic Python, but in Ruby the idiomatic is def date_string(year = true). Personally I don't like positional optional values, specially booleans; when you call them you have no idea what the argument stands for. You can use an options hash instead. Do you remember the old Rails obj.save(false)? wisely changed in Rails 3 to obj.save(:validate => false).How to build string with conditional values: This is the pattern I use:str = [%B %e, *(, %Y if year)].jointhe else returns an empty string, why? it's better if it returns nil.Check String#squish.To sum it up, I'd write the first method like this:def date_string(options = {})  format = [%B %e, *(, %Y if options[:year])].join  date.strftime(format).squishendJust as a side note: does it make sense to have all these methods in a model? (or a presenter, it doesn't matter). Think of an orthogonal approach, create helper methods available for everbody to use (and send them date object), this way you achieve real modularity.