-1
我正在創建一個應用程序,它使用帶有數字和名稱的JSON文件發送大量文本。我每次試驗載荷在IRB應用程序出現錯誤:在大量文本應用程序中獲取未定義的錯誤
NameError: undefined local variable or method `data_from_file' for main:Object
from /home/qc/tep/Coding Stuff/Ruby/text app/main.rb:14:in `contacts_from_file'
我明白什麼錯誤意味着,但我不明白爲什麼我得到的錯誤,這裏的源代碼:
require 'json'
def sanatize(numbers)
"+1" + number.gsub(/^1|\D/, "")
end
def numbers_from_file
file = open('numbers.json').read
JSON.parse(file)
end
def contacts_from_file
contacts= { }
data_from_file['feed']['entry'].each do |entry|
name = entry['gsx$name']['$t']
number = entry['gsx$number']['$t']
contacts[sanatize(number)] = name
end
contacts
end
def contact_numbers
contacts_from_file.keys
end
def contact_name
contacts_from_file[number]
end
而這裏的JSON文件:
{
'1**********' => 'Big Bird'
'1**********'} => 'Josh'
}
如果有人可以幫助我,告訴我爲什麼data_from_file
是「不確定」這將是非常有益的,謝謝你的時間提前。
「並告訴我爲什麼data_from_file未定義」 - 好吧,因爲您沒有定義它,這就是爲什麼。 –