[ruby-core:117722] [Ruby master Feature#20444] Kernel#loop: returning the "result" value of StopIteration doesn't work when raised directly
From:
"nobu (Nobuyoshi Nakada) via ruby-core" <ruby-core@...>
Date:
2024-04-26 08:28:27 UTC
List:
ruby-core #117722
Issue #20444 has been updated by nobu (Nobuyoshi Nakada).
That example does not need `Ractor`.
```ruby
class MyStop < ::StopIteration
attr_reader :result
def initialize(result)
@result = result
end
end
block = proc {raise StopIteration, 3}
p Thread.start {loop {block.call}}.value #=> nil
block = proc { raise MyStop, 3 }
p Thread.start {loop {block.call}}.value #=> 3
```
----------------------------------------
Feature #20444: Kernel#loop: returning the "result" value of StopIteration doesn't work when raised directly
https://bugs.ruby-lang.org/issues/20444#change-108130
* Author: esad (Esad Hajdarevic)
* Status: Feedback
----------------------------------------
There was a https://bugs.ruby-lang.org/issues/11498 a while ago which was merged in, but I was surprised to find out that raising `StopIteration` in a loop like
`loop { raise StopIteration.new(3) }`
returns nil and not 3.
--
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/