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

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

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

unit testing - How to mock PreferenceManager in Android? -