undefined local variable or method '_1' for main:Object運行以下代碼時出現錯誤。知道為什么我會收到此錯誤嗎?以及如何將結果存盤在變數中。
result="-e hostname=webserver001 -e username=root -e password=testing123"
p result.scan(/\w =\w /)
.map { _1.split("=") }
.to_h
Error:
Traceback (most recent call last):
2: from main.rb:4:in `<main>'
1: from main.rb:4:in `map'
main.rb:4:in `block in <main>': undefined local variable or method `_1' for main:Object (NameError)
exit status 1
uj5u.com熱心網友回復:
您可能正在運行舊版本的 ruby?? - 自 2.7 以來,塊的編號引數已在 ruby?? 中可用 - 請參閱https://www.bigbinary.com/blog/ruby-2-7-introduces-numbered-parameters-as -默認塊引數
您可以通過使用使其在舊版本上作業
p result.scan(/\w =\w /)
.map { |s| s.split("=") }
.to_h
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/440694.html
標籤:红宝石
