1 Why does this output 1 instead of 4?" /> 1 Why does this output 1 instead of 4?" /> 1 Why does this output 1 instead of 4?"/>

Ruby docs rindex example

48 Views Asked by At

This example is from the ruby docs.

"hello".rindex(/[aeiou]/, -2)   #=> 1

Why does this output 1 instead of 4?

1

There are 1 best solutions below

1
Ursus On BEST ANSWER

Because the second parameter. From the doc

If the second parameter is present, it specifies the position in the string to end the search—characters beyond this point will not be considered.

So

"hello".rindex(/[aeiou]/)
 => 4