"Undefined method `gsub!'" when executes a Ruby filter to change timezone

I am unable to reproduce the issue, but this

input { generator { count => 1 lines => [ '2018-11-02 14:31:01' ] } }

filter {
    date {
        match => ["message", "yyyy-MM-dd HH:mm:ss"]
        target => "justtime"
    }
    ruby {
        init => 'require "time"'
        code => '
            t = event.get("justtime").to_s
            event.set("newtime", Time.parse(t).localtime("-07:00").strftime("%Y-%m-%d %H:%M:%S"))
        '
    }
}

produces

   "newtime" => "2018-11-02 11:31:01",
  "justtime" => 2018-11-02T18:31:01.000Z