将对象推入约会数组
Push object onto appointments array
我必须将来自 appt2 的信息放入我的约会数组中。
我目前拥有的:
appointments = []
appt2 = MonthlyAppointment.new("Doctor", "Cold", 2, 30, 15)
appointments.push(appt2)
我能解决什么问题?
如果你只做一件事,你可以去掉中间变量:
appointments = [
MonthlyAppointment.new(...)
]
您可以为 push
使用 <<
别名:
appointments << appt2
您拥有的是相当典型的 Ruby 代码。
我必须将来自 appt2 的信息放入我的约会数组中。
我目前拥有的:
appointments = []
appt2 = MonthlyAppointment.new("Doctor", "Cold", 2, 30, 15)
appointments.push(appt2)
我能解决什么问题?
如果你只做一件事,你可以去掉中间变量:
appointments = [
MonthlyAppointment.new(...)
]
您可以为 push
使用 <<
别名:
appointments << appt2
您拥有的是相当典型的 Ruby 代码。