我不断收到此错误:
event_manager.rb:83:in
': 未定义的方法output_data' for #<EventManager:0x007fc5018320c0> (NoMethodError)
我正在关注这个网站上的练习:
这是我的代码(我的错误以DEF OUTPUT_DATA
...结尾):
# Dependencies
require "csv"
# Class Definition
class EventManager
INVALID_PHONE_NUMBER = "0000000000"
INVALID_ZIPCODE = "00000"
def initialize
puts "EventManager Initialized."
filename = "event_attendees.csv"
@file = CSV.open(filename, {:headers => true, :header_converters => :symbol})
end
def print_names
@file.each do |line|
puts line.inspect
puts line[2] + " " + line[3]
end
end
#printing home phone number method
def print_numbers
@file.each do |line|
number = clean_number(line[:homephone])
puts number
end
end
#cleaning numbers method
def clean_number(number)
cleaner= number.delete('.' + ')' + '(' + '-')
if cleaner.length == 10
# Do Nothing
elsif cleaner.length == 11
if cleaner.start_with?("1")
cleaner = cleaner[1..-1]
else
cleaner = INVALID_PHONE_NUMBER
end
else
cleaner = INVALID_PHONE_NUMBER
end
return cleaner
end
def clean_zipcode(original)
if original.nil?
zipcode = INVALID_ZIPCODE
elsif original.length < 5
while original.length < 5
original = original.insert(0, "0")
end
else
return original
end
return zipcode
end
def print_zipcodes
@file.each do |line|
zipcode = clean_zipcode(line[:zipcode])
puts zipcode
end
def output_data
output = CSV.open("event_attendees_clean.csv", "w")
@file.each do |line|
output << line
end
end
end
end
# Script
manager = EventManager.new
#manager.print_numbers
#manager.print_zipcodes
manager.output_data
我已经尝试了几件事,通过互联网检查了所有内容,但我自己无法弄清楚。
我将非常感谢任何帮助。
先感谢您!