[#116016] [Ruby master Bug#20150] Memory leak in grapheme clusters — "peterzhu2118 (Peter Zhu) via ruby-core" <ruby-core@...>
Issue #20150 has been reported by peterzhu2118 (Peter Zhu).
7 messages
2024/01/04
[#116382] [Ruby master Feature#20205] Enable `frozen_string_literal` by default — "byroot (Jean Boussier) via ruby-core" <ruby-core@...>
Issue #20205 has been reported by byroot (Jean Boussier).
77 messages
2024/01/23
[ruby-core:116161] [Ruby master Feature#20164] Add Exception#deconstruct_keys
From:
"palkan (Vladimir Dementyev) via ruby-core" <ruby-core@...>
Date:
2024-01-10 22:32:22 UTC
List:
ruby-core #116161
Issue #20164 has been updated by palkan (Vladimir Dementyev).
+1 for making exceptions pattern-matching friendly. The example above demonstrates the use case pretty well (class + message matching).
The question is what keys must be supported for each standard exception class? The plain Ruby implementation could be as follows:
```ruby
class Exception
# Not sure if we need to take into account the `keys` argument
def deconstruct_keys(*) = {message:, cause:}
end
class NameError
def deconstruct_keys(*) = super.merge(name:)
end
```
----------------------------------------
Feature #20164: Add Exception#deconstruct_keys
https://bugs.ruby-lang.org/issues/20164#change-106167
* Author: Dan0042 (Daniel DeLorme)
* Status: Open
* Priority: Normal
----------------------------------------
It would be convenient to perform pattern matching with exception classes. So `Exception#deconstruct_keys` should return a hash with `:message` (original_message) as well as any other keys specific to the exception subclass.
Examples:
```
begin
#code
rescue => err
case err
in StandardError(message: /Permission denied/)
abort "please select a different file"
in NameError(name: :foo)
retry if require "foo_helper
else
raise
end
end
```
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- [email protected]
To unsubscribe send an email to [email protected]
ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/