From: "mame (Yusuke Endoh) via ruby-core" Date: 2024-11-26T18:28:07+00:00 Subject: [ruby-core:120015] [Ruby master Bug#20911] Array#max doesn't take block if using &: Issue #20911 has been updated by mame (Yusuke Endoh). Status changed from Open to Rejected `Array#max` accepts a block that compares two values. ``` p ["1", "2", "3"].max {|i, j| i.to_i <=> j.to_i } #=> "3" ``` You may want to use `Array#max_by`. ``` p ["1", "2", "3"].max_by(&:to_i) #=> "3" ``` ---------------------------------------- Bug #20911: Array#max doesn't take block if using &: https://bugs.ruby-lang.org/issues/20911#change-110755 * Author: alvitovitch@gmail.com (Andrew Vitovitch) * Status: Rejected * ruby -v: ruby 3.3.5 * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- ["1","2","3"].max { |i| i.to_i } => "3" ["1","2","3"].max(&:to_i) (irb):6:in `to_i': no implicit conversion of String into Integer (TypeError) ["1","2","3"].max(&:to_i) ^^^^^^ from (irb):6:in `max' from (irb):6:in `
' from :187:in `loop' from /Users/alvitovitch/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/irb-1.13.1/exe/irb:9:in `' from /Users/alvitovitch/.asdf/installs/ruby/3.3.5/bin/irb:25:in `load' from /Users/alvitovitch/.asdf/installs/ruby/3.3.5/bin/irb:25:in `
' -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/