Created
March 26, 2012 23:03
-
-
Save ryangreenberg/2210448 to your computer and use it in GitHub Desktop.
todo_for_real
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'date' | |
class ExpiredTodoError < StandardError; end | |
# Implementation # | |
def todo(what, by_date) | |
if production? || (Date.parse(by_date) >= Date.today) | |
yield | |
else | |
raise ExpiredTodoError, "TODO: #{what}" | |
end | |
end | |
# Would actually be Rails.env.production? or something similar # | |
def production? | |
false | |
end | |
# Sample usage # | |
todo("Make this code less janky", "4/1/2012") do | |
o = Object.new | |
Marshal.load(Marshal.dump(o)) | |
end |
Haha. Fun idea. Would rather you raise ExpiredTodoError
or something similar though.
Production guard seems unnecessary.
todo("Make this code less janky", Chronic.parse('next Tuesday')) do
#foo
end
See, this is what happens when someone has an idea.
slight alteration to the to_do_or_else would be:
to_do_or_die
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
shipit if you rename "todo" to "todo_or_else"