なるようになるブログ

読書感想文かrailsについてかrubyについてか

rails commit log流し読み(2021/04/19)

2021/04/19分のコミットです。

CHANGELOGにのったコミットは以下の通りです。

activesupport/CHANGELOG.md


Add Enumerable#sole (#40914)

activesupport/lib/active_support/core_ext/enumerable.rbの修正です。

Enumerableに、1レコードを取得、かつ、レコードが1つじゃない場合にexceptionをraiseするEnumerable#soleを追加しています。Add ActiveRecord::FinderMethods#sole and #find_sole_by で追加されたActiveRecord::FinderMethods#soleEnumerable版。

["x"].sole          # => "x"
Set.new.sole        # => Enumerable::SoleItemExpectedError: no item found
{ a: 1, b: 2 }.sole # => Enumerable::SoleItemExpectedError: multiple items found