From: zverok.offline@... Date: 2016-05-05T14:05:29+00:00 Subject: [ruby-core:75369] [Ruby trunk Feature#12350] Introduce Array#find! that raises an error if element not found Issue #12350 has been updated by Victor Shepelev. > Could you elaborate what is bad in your example? Basically I don't see anything bad in your code except a little bit verbose like in mine solution. I don't know! The most popular and widely accepted Ruby Style Guide just bans them: https://github.com/bbatsov/ruby-style-guide#no-and-or-or And when I've tried to rant about how and/or are useful, it all went sideways: https://www.reddit.com/r/ruby/comments/478a17/rant_on_good_ruby_idiom_andor_operators/ ---------------------------------------- Feature #12350: Introduce Array#find! that raises an error if element not found https://bugs.ruby-lang.org/issues/12350#change-58494 * 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: