Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ruby NoMethodError中未定义的方法错误_Ruby - Fatal编程技术网

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