每当我运行此代码时,我想要的名称都没有正确输入到数组中。输出等于#=> RandomUserName #=> ["测试",""] 它非常烦人,如果有人想出如何将随机用户名输入数组,那将会很棒。
#!/usr/bin/env ruby
require 'mechanize'
require 'open-uri'
testarray = ["test" ].compact
password = "456789solid"
url = "http://namegeneratorbay.com/username-generator"
userdata = Nokogiri::HTML(open(url))
username1 = puts userdata.at_css('h2').text.strip
final1 = username1.to_s
testarray.push("#{final1}")
print testarray
sleep(10)
答案 0 :(得分:2)
class ClassA {
let xSize = 6 // whatever
let ySize = 6 // whatever
let StructAMap: Array<Array<StructA>>
init() {
var StructAMap = Array(count: ySize, repeatedValue:
Array(count: xSize, repeatedValue: StructA()))
for help in 1...2 {
StructAMap[help][1].id = Segments.s1
StructAMap[help][1].parent = Segments.noParent
StructAMap[help][1].value = 0.0
StructAMap[help][2].id = Segments.s2
StructAMap[help][2].parent = Segments.s1
// etc...
}
StructAMap[1][3].id = Segments.s1
StructAMap[2][3].value = 3.0
// etc...
self.StructAMap = StructAMap
}
}
的返回值为puts userdata.at_css('h2').text.strip
,因此nil
为username1
。
请改为尝试:
nil