ruby NoMethodError中未定义的方法错误
以下代码返回错误,我不知道原因:ruby NoMethodError中未定义的方法错误,ruby,Ruby,以下代码返回错误,我不知道原因: require "rexml/document" include REXML file = File.new("test.xml") doc = REXML::Document.new file class Registration attr_accessor :number, :jurisdiction, :physicallyPresentInRegistrationCountry end def constructRegistrat
require "rexml/document"
include REXML
file = File.new("test.xml")
doc = REXML::Document.new file
class Registration
attr_accessor :number, :jurisdiction, :physicallyPresentInRegistrationCountry
end
def constructRegistration(item, typeOfMerchant)
reg = Registration.new
element = item.elements[typeOfMerchant + "PhysicallyPresentInRegistrationCountry"]
if element != nil then
reg,physicallyPresentInRegistrationCountry = element.text
else
reg.physicallyPresentInRegistrationCountry = nil
end
return reg
end
XPath.each(doc, "//transactionAuditRecordList/item") { |item|
reg = constructRegistration(item, "seller")
puts reg.physicallyPresentInRegistrationCountry
}
rexml.rb:26:未定义“false”的“physicallyPresentInRegistrationCountry”方法:String(NoMethodError)
看起来像一个散乱的逗号,而不是一个点:
if element != nil then
reg,physicallyPresentInRegistrationCountry = element.text
#----^^^^
这会对注册国家的两个变量reg
和physicallyPresentInRegistrationCountry
执行多重赋值,但只有=
右侧的一个表达式表示
reg = element.text
physicallyPresentInRegistrationCountry = nil
reg = element.text
physicallyPresentInRegistrationCountry = nil