ruby on rails - Date and Time in ROR -


in app want time/date display month/year (e.g. 7/10). problem class date , class time wind following code in application controller ...

class date   def as_month_and_year     self.strftime("%m").to_i.to_s + self.strftime("/%y")   end end  class time   def as_month_and_year     self.strftime("%m").to_i.to_s + self.strftime("/%y")   end end 

what's best way dry up?

imho more elegant solution:

module datetimeextensions   def as_months_and_year     self.strftime('%m/%y').sub(/^0/,'')   end   [time, date, datetime].each{ |o| o.send :include, self } end 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -