Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/core_ext/date.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
})
}
7 changes: 7 additions & 0 deletions lib/core_ext/object.rb
Original file line number Diff line number Diff line change
@@ -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
18 changes: 1 addition & 17 deletions lib/core_ext/time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
1 change: 1 addition & 0 deletions lib/localized_dates.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'core_ext/object'
require 'core_ext/date'
require 'core_ext/datetime'
require 'core_ext/time'
Expand Down