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'