问题描述
|
我创建了一个跟踪汽车行驶里程和服务历史记录的程序,以便为用户更新汽车的近期服务需求。
我有三个班级:
Car
,CarHistory
和CarServiceHistoryEntry
。第三个很简单;它包含与服务相关的所有属性:日期,里程,执行的服务等。“ 1”类如下:
require_relative \'car_service_history_entry\'
class CarHistory
attr_reader :entries
def initialize (*entry)
if entry.size > 1
@entries = []
else
@entries = entry
end
end
def add_service_entry entry
@entries << entry
end
def to_s
entries_string = \"\"
@entries.each {|entry| entries_string << \"#{entry.to_s}\\n\"}
entries_string
end
end
在initialize
中,应该检查entry
的等级吗?
在ѭ7中,采用鸭子类型(如“编程Ruby”中Andy Thomas的论点),我什至会测试是否可以添加CarServiceHistoryEntry
吗?我不能通过a9而不是设置然后在我的单元测试中添加ѭ2吗?
由于CarHistory
唯一必要的属性是entries
数组和to_s
方法,我是否应该将所有此类都废弃,然后将其放入car
类中?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)