mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
fix multiple value support of max_by; ref #1912
This commit is contained in:
@@ -278,7 +278,7 @@ module Enumerable
|
||||
#
|
||||
# If no block is given, an enumerator is returned instead.
|
||||
#
|
||||
# %w[albatross dog horse].max_by { |x| x.length } #=> "albatross"
|
||||
# %w[albatross dog horse].max_by {|x| x.length } #=> "albatross"
|
||||
|
||||
def max_by(&block)
|
||||
return to_enum :max_by unless block_given?
|
||||
@@ -290,16 +290,15 @@ module Enumerable
|
||||
self.each do |*val|
|
||||
if first
|
||||
max = val.__svalue
|
||||
max_cmp = block.call(val.__svalue)
|
||||
max_cmp = block.call(*val)
|
||||
first = false
|
||||
else
|
||||
if cmp = block.call(val.__svalue) > max_cmp
|
||||
if cmp = block.call(*val) > max_cmp
|
||||
max = val.__svalue
|
||||
max_cmp = cmp
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
max
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user