Skip to content

Instantly share code, notes, and snippets.

@mcfiredrill
Last active December 19, 2015 23:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcfiredrill/cbf120e63fad37087195 to your computer and use it in GitHub Desktop.
Save mcfiredrill/cbf120e63fad37087195 to your computer and use it in GitHub Desktop.
class NullDate
include Comparable
def to_s
""
end
def <=> other_date
Time.new(0000,1,1) <=> other_date
end
def to_date
""
end
def to_datetime
end
def strftime format
"No data yet."
end
# just in case...
def blank?
true
end
end
█▓▒░tony@matsuri░▒▓█ ~/src/app(development)$ irb
[1] pry(main)> require './lib/null_date'
=> true
[2] pry(main)> Time.new(2013,3,3) > NullDate.new
=> true
[3] pry(main)> NullDate.ancestors
=> [NullDate, Comparable, Object, PP::ObjectMixin, Kernel, BasicObject]
█▓▒░tony@matsuri░▒▓█ ~/src/app(development)$ ./script/rails c
Loading development environment (Rails 3.2.13)
[1] pry(main)> Time.new(2013,3,3) > NullDate.new
ArgumentError: comparison of Time with NullDate failed
from (pry):1:in `>'
[2] pry(main)> NullDate.ancestors
=> [NullDate,
Comparable,
Object,
Metaclass::ObjectMethods,
Mocha::ObjectMethods,
PP::ObjectMixin,
JSON::Ext::Generator::GeneratorMethods::Object,
ActiveSupport::Dependencies::Loadable,
Kernel,
BasicObject]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment