https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112022-08-03T04:52:55ZRuby Issue Tracking SystemRuby master - Bug #18953: `Array#uniq` doesn't evaluate the given block when the size of the array is onehttps://bugs.ruby-lang.org/issues/18953?journal_id=985702022-08-03T04:52:55Zmrkn (Kenta Murata)muraken@gmail.com
<ul></ul><p>I hope this behavior should be expected.<br>
However, <code>sort_by</code>, <code>max_by</code>, and <code>min_by</code> call the given blocks even if the receiver array has only one item.</p>
<pre><code>irb(main):001:0> [42].sort_by { _1.foo }
(irb):1:in `block in <top (required)>': undefined method `foo' for 42:Integer (NoMethodError)
Did you mean? floor
from (irb):1:in `each'
from (irb):1:in `sort_by'
from (irb):1:in `<main>'
from /home/mrkn/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/irb-1.4.1/exe/irb:11:in `<top (required)>'
from /home/mrkn/.rbenv/versions/3.1.0/bin/irb:25:in `load'
from /home/mrkn/.rbenv/versions/3.1.0/bin/irb:25:in `<main>'
irb(main):002:0> [42].max_by { _1.foo }
(irb):2:in `block in <top (required)>': undefined method `foo' for 42:Integer (NoMethodError)
Did you mean? floor
from (irb):2:in `each'
from (irb):2:in `max_by'
from (irb):2:in `<main>'
from /home/mrkn/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/irb-1.4.1/exe/irb:11:in `<top (required)>'
from /home/mrkn/.rbenv/versions/3.1.0/bin/irb:25:in `load'
from /home/mrkn/.rbenv/versions/3.1.0/bin/irb:25:in `<main>'
irb(main):003:0> [42].min_by { _1.foo }
(irb):3:in `block in <top (required)>': undefined method `foo' for 42:Integer (NoMethodError)
Did you mean? floor
from (irb):3:in `each'
from (irb):3:in `min_by'
from (irb):3:in `<main>'
from /home/mrkn/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/irb-1.4.1/exe/irb:11:in `<top (required)>'
from /home/mrkn/.rbenv/versions/3.1.0/bin/irb:25:in `load'
from /home/mrkn/.rbenv/versions/3.1.0/bin/irb:25:in `<main>'
</code></pre> Ruby master - Bug #18953: `Array#uniq` doesn't evaluate the given block when the size of the array is onehttps://bugs.ruby-lang.org/issues/18953?journal_id=985712022-08-03T06:12:48Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>I think this is an expected behavior, but an implementation detail.</p> Ruby master - Bug #18953: `Array#uniq` doesn't evaluate the given block when the size of the array is onehttps://bugs.ruby-lang.org/issues/18953?journal_id=986172022-08-09T16:52:50Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Rejected</i></li></ul>