注册 登录
编程论坛 Ruby论坛

帮忙用RUBY写个时间代码

h6662858 发布于 2009-07-30 19:07, 2991 次点击
假定:登陆用户在网页上写日志并提交,从提交开始过了48小时就不允许编辑此日志内容,请就此限制用户操作日志时间写个代码

急需要,不胜感激,在线等,谢谢各位大侠
1 回复
#2
try_catch2011-06-17 04:07
你起码得给个strucutre吧。。比如你有什么object干什么之类的

class journal

    attr_accessor    :start_time

    def initialize
        #your code....
        @start_time = Time.now
    end

    def edit
        if timeout
            #cannot change your journal, return
            return false
        end
        ....
    end

    def timeout
        if Time.now - @start_time > 48*24*3600    #ruby use second as standard unit for time
            return true
        end
        return false
    end
end

1