From 11160b53c91fd7b5aa92e76e8d1750e711f5a20b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Azimi?= Date: Thu, 14 Jun 2012 14:47:30 +0200 Subject: [PATCH] DATE_FORMATS warning issue fixed. --- lib/core_ext/date.rb | 4 ++-- lib/core_ext/object.rb | 7 +++++++ lib/core_ext/time.rb | 18 +----------------- lib/localized_dates.rb | 1 + 4 files changed, 11 insertions(+), 19 deletions(-) create mode 100644 lib/core_ext/object.rb diff --git a/lib/core_ext/date.rb b/lib/core_ext/date.rb index 9bae8b6..4d760e6 100644 --- a/lib/core_ext/date.rb +++ b/lib/core_ext/date.rb @@ -14,8 +14,8 @@ def to_formatted_s(format = :default) alias_method :to_s, :to_formatted_s end -::Date.const_set('DATE_FORMATS', { +::Date.redef_without_warning :DATE_FORMATS, { :db => "%Y-%m-%d", :number => "%Y%m%d", :rfc822 => "%e %b %Y" -}) \ No newline at end of file +} diff --git a/lib/core_ext/object.rb b/lib/core_ext/object.rb new file mode 100644 index 0000000..da0a5e9 --- /dev/null +++ b/lib/core_ext/object.rb @@ -0,0 +1,7 @@ +class Object + def redef_without_warning(const, value) + mod = self.is_a?(Module) ? self : self.class + mod.send :remove_const, const + mod.const_set(const, value) + end +end diff --git a/lib/core_ext/time.rb b/lib/core_ext/time.rb index 5467422..65fd8d4 100644 --- a/lib/core_ext/time.rb +++ b/lib/core_ext/time.rb @@ -14,24 +14,8 @@ def to_formatted_s(format = :default) alias_method :to_s, :to_formatted_s end -class Object - def def_if_not_defined(const, value) - mod = self.is_a?(Module) ? self : self.class - mod.const_set(const, value) unless mod.const_defined?(const) - end - - def redef_without_warning(const, value) - mod = self.is_a?(Module) ? self : self.class - if defined?(const.constantize) and mod.const_defined?(const) - mod.send(:remove_const, const) - else - mod.const_set(const, value) - end - end -end - ::Time.redef_without_warning :DATE_FORMATS, { :db => "%Y-%m-%d %H:%M:%S", :number => "%Y%m%d%H%M%S", :rfc822 => "%a, %d %b %Y %H:%M:%S %z" -} \ No newline at end of file +} diff --git a/lib/localized_dates.rb b/lib/localized_dates.rb index a7f1483..e964f73 100644 --- a/lib/localized_dates.rb +++ b/lib/localized_dates.rb @@ -1,3 +1,4 @@ +require 'core_ext/object' require 'core_ext/date' require 'core_ext/datetime' require 'core_ext/time'