此时,我只是尝试使用命令行从文件中显示一些基本行。
继承我的模块:
require "reverb_exercise/version"
module ReverbExercise
class Parser
attr_accessor :records
def parse_file(file)
@lines = []
File.open(file, "r") do |file|
file.each_line do |line|
@lines << line
end
end
@lines
end
def build_records
@records = []
@lines.each do |line|
@records << Record.new(*line.split(", "))
end
@records
end
end
class Record
attr_accessor :first_name, :last_name, :gender, :color, :birthdate
def initialize(first_name, last_name, gender, color, birthdate)
@first_name = first_name
@last_name = last_name
@gender = gender
@color = color
@birthdate = birthdate
end
end
end
这是bin文件夹:
#!/usr/bin/env ruby
require 'reverb_exercise'
puts ReverbExercise::Parser.new.parse_file("comma.txt")
当我在终端中运行reverb
时,收到以下undefined local variable or method
错误:
Users / yedidyaweiner / .rbenv / versions / 2.1.2 / lib / ruby / gems / 2.1.0 / gems / reverb_exercise-0.0.1 / lib / reverb_exercise.rb:10:in
block (2 levels) in parse_file': undefined local variable or method
lines' for#(NameError)
我错过了什么?