From: coorasse@... Date: 2018-04-18T10:11:24+00:00 Subject: [ruby-core:86577] [Ruby trunk Feature#14672] Introduce a Date.safe_parse method Issue #14672 has been updated by coorasse (Alessandro Rodi). As pointed out by @ahorek, is not really good to use, raise, catch exceptions in ruby because yes...they are slow. A one line rescue is what I used in the past, but it feels hacky and is a catch-all rescue which is never a good approach. In the end, rubocop now defines it as bad practice and corrects it automatically. See also https://robots.thoughtbot.com/don-t-inline-rescue-in-ruby ---------------------------------------- Feature #14672: Introduce a Date.safe_parse method https://bugs.ruby-lang.org/issues/14672#change-71519 * 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: