From: janfri26@... Date: 2018-04-11T14:29:29+00:00 Subject: [ruby-core:86510] [Ruby trunk Feature#14672] Introdice a Date.safe_parse method Issue #14672 has been updated by janfri (Jan Friedrich). Why not use a one line rescue? ~~~ ruby Date.parse(some_value) rescue Date.new(2018,1,1) ~~~ It shows IMHO the intention very clear. ---------------------------------------- Feature #14672: Introdice a Date.safe_parse method https://bugs.ruby-lang.org/issues/14672#change-71452 * Author: coorasse (Alessandro Rodi) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- This feature request is about a Date.safe_parse method. The method should call the original Date.parse method but avoid raising an exception and returning a fallback value instead. An implementation in ActiveSupport has been proposed here: https://github.com/rails/rails/pull/32503/files. This would avoid the necessity to rescue possible Exceptions everytime. See: ```ruby Date.safe_parse(nil) => # nil Date.safe_parse("") => # nil fallback = Date.new(2018,1,1) Date.safe_parse(nil, fallback) => # # ``` -- https://bugs.ruby-lang.org/ Unsubscribe: