2012-05-17 22 views
-1

当我尝试运行我的文件为什么str.scan在运行文件时无法工作?

$ ruby file.rb

我得到

file.rb:5:in `<main>': undefined local variable or method `str' for main:Object (NameError) 

的文件似乎并没有认识到str.scan。我的线是

@file_split = str.scan(/ \+\d{11} /) 

我错过了我应该要求的东西?

修正:我错过了变量名!

+0

什么'str'?你错过了一个变量。 –

+0

你可以显示你正在定义str的位置吗? – Genzume

回答

2

str变量应该在file.rb中初始化。例如这样的:

str = ' +45754646467 ' 

,然后你的事情

@file_split = str.scan(/ \+\d{11} /) 
相关问题