h6662858 发表于 2009-7-30 19:07

帮忙用RUBY写个时间代码

假定:登陆用户在网页上写日志并提交,从提交开始过了48小时就不允许编辑此日志内容,请就此限制用户操作日志时间写个代码

急需要,不胜感激,在线等,谢谢各位大侠

try_catch 发表于 2011-6-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]

编程论坛