Skip to content

Instantly share code, notes, and snippets.

@bf4
Forked from anonymous/string_to_date.rb
Last active December 10, 2015 02:48
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 bf4/4370014 to your computer and use it in GitHub Desktop.
Save bf4/4370014 to your computer and use it in GitHub Desktop.
# 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
block_given? ? yield : raise
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment