str[regexp]
на самом деле является методом класса String, вы можете найти его здесь http://www.ruby -doc.org / core / classes / String.html # M001128
Второй аргумент 1
вернет текст, соответствующий первому подшаблону #coding[:=].*\r?\n
, еще один пример для вашего лучшего понимания:
"ab123baab"[/(\d+)(ba+).*/, 0] # returns "123baab", since it is the complete matched text, ,0 can be omitted also
"ab123baab"[/(\d+)(ba+).*/, 1] # returns "123", since the first subpattern is (\d+)
"ab123baab"[/(\d+)(ba+).*/, 2] # returns "baa", since the second subpattern is (ba+)