lib/my_age/cli.rb in my_age-0.1.5 vs lib/my_age/cli.rb in my_age-0.1.6

- old
+ new

@@ -12,24 +12,26 @@ self.dob = get_date(options[:dob]) date = options[:as_of].present? ? get_date(options[:as_of]) : Date.today puts self.age(date) end - private def get_date(date) if date =~ /^\d{4}-\d{2}-\d{2}$/ DateTime.strptime(date, "%Y-%m-%d") else - dates = date.delete(")").split("(") - if dates.length == 2 - Date.today.send(dates[0].to_sym, dates[1].to_i) - else - Date.today.send(dates[0].to_sym) - end + date_from_active_support_core_ext_helper(date) end rescue NoMethodError Date.send(date) + end + + def date_from_active_support_core_ext_helper(date) + dates = date.delete(")").split("(") + method = dates[0].to_sym + arg = dates[1] + arg.nil? ? Date.today.send(method) : + Date.today.send(method, arg.to_i) end end end