【发布时间】:2020-02-24 12:54:59
【问题描述】:
我试图让日期成为我的哈希键,然后让余额的总和成为我的哈希数组中的值,以便稍后在返回将打印日期、金额和余额的帐户对帐单时使用哈希。
代码如下:
class Bank
attr_accessor :total, :time
def initialize
@total = 0
@time = [:date => @total]
end
def deposit(sum)
@total += sum
end
def withdrawl(sum)
@total -= sum
end
def input_time
@time << Time.now.strftime('%d/%-m/%Y')
end
def yesterday
@time << Time.at(Time.now.to_i - 86400).strftime('%d/%-m/%Y')
end
end
如何让日期成为哈希键?我目前正在尝试将其附加,但这只是添加到数组中。
【问题讨论】: