[#76442] [Ruby trunk Feature#11741] Migrate Ruby to Git from Subversion — naruse@...
Issue #11741 has been updated by Yui NARUSE.
3 messages
2016/07/19
[#76515] [Ruby trunk Bug#12610] webrick: protect from httpoxy — nagachika00@...
Issue #12610 has been updated by Tomoyuki Chikanaga.
3 messages
2016/07/22
[ruby-core:76413] [Ruby trunk Feature#12350] Introduce Array#find! that raises an error if element not found
From:
matz@...
Date:
2016-07-19 06:20:33 UTC
List:
ruby-core #76413
Issue #12350 has been updated by Yukihiro Matsumoto.
I am not against adding a method that raises an exception, but `find!` is not a proper name for it.
Besides that, we can raise an exception for non-existing values by the current behavior.
So let us start improving documentation. Daniel, could you create an PR?
Matz.
----------------------------------------
Feature #12350: Introduce Array#find! that raises an error if element not found
https://bugs.ruby-lang.org/issues/12350#change-59653
* Author: Andrey Koleshko
* Status: Open
* Priority: Normal
* Assignee:
----------------------------------------
It would be great to have some function (like `Hash#fetch`) for `Array` that raises an exception if element not found by passed block in `find`.
For example:
~~~
[].find! { |el| el == 1 }
=> ElementError: element not found
~~~
I just noticed that there are many cases when it's needed to raise an exception (because this is exceptional situation) if an element not found.
Currently I just define methods like this one:
~~~
def find_price!(size)
found_price = prices.find { |p| p.key == size }
fail "Price for #{size} not found" unless found_price
found_price
end
~~~
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>