Skip to content

Instantly share code, notes, and snippets.

Created December 24, 2012 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/4370010 to your computer and use it in GitHub Desktop.
Save anonymous/4370010 to your computer and use it in GitHub Desktop.
string to date parsing trick
# method to evaluate the block for a default value if the
# conversion to date fails
# string.to_date return nil if the string is blank
# so we yield to get the default value from the block there
# or on a parse error
def string_to_date(string,&block)
string.to_date || yield
rescue => e
yield
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment