I have following code:
date_time = Time.now.strftime('%Y%m%d%H%M%S')
name = "builder-#{date_time}" # builder-20150923125450
if some_condition
name.sub!("#{date_time}", "one-#{date_time}") # builder-one-20150923125450
end
Above code is working fine.
But I think it could be better as I feel like I am repeating #{date_time} twice here.
I have heard of regex capture and replace. Can we use it here? If yes, how?
name, and you have to modify it?['builder', ('one' if cond), date_time].compact.join('-')['builder', *('one' if cond), date_time].join('-').*!