我正在研究 ruby,不知何故,我将一些方法定义为私有方法,但出现错误:“类的未定义方法私有......”。我在下面发布了我的代码。任何帮助或建议都可以!谢谢 :)
代码:
class Bot
attr_reader :name
def initialize(options)
@name = options[:name] || "Unnamed Bot"
begin
@data = YAML.load(File.read(options[:data_file]))
rescue
raise "Could not load bot data"
end
private
def random_response(key)
random_index = rand(@data[:responses][key].length)
@data[:responses][key][random_index].gsub(/\[name\]/, @name)
end
def greeting
random_response :greeting
end
def farewell
radnom_response :farewell
end
def response_to(input)
prepared_input = preprocess(input).downcase
end
def preprocess(input)
perform_substitutions input
end
end
end
错误: