Forum: Ruby-Forum.com max_by and other methods simply not working

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
8a2d3e0301b8f9e21fd1511cb0bea91b?d=identicon&s=25 Anna Hl (ann_n)
on 2017-04-22 04:22
Hello to everyone!

I am quite new to ruby and I'm simply wanted to find the longest number
sequence in an array like this:

string = input.scan(/(\d+)/)
string.max_by(&:length)

However, in the output I get only the first value in the array.
I tried to use other methods, just to test how they would work and
turned out that none of them work, even those that I've copied from
working examples. What can be wrong?
The whole code is:

puts "Enter a string with letters and numbers"
input = gets
string = input.scan(/(\d+)/)
puts string.max_by(&:length)

Thanks for any help!
This topic is locked and can not be replied to.