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)
some_string.scan(/(\d+)/).flatten.max_by(&:length) or some_string.scan(/(\d+)/).join(' ').split.max_by(&:length) or some_string.scan(/(\d+)/).map(&:first).max_by(&:length)
Explanation
When you use scan(/(\d+)/) method on a String object, it will just scan for digits, and group them in an array. For example: