Ruby solution
Code\nruby []\nclass SnapshotArray\n\n=begin\n  :type length: Integer\n=end\n  def initialize(length)\n    @current_snapshot_id = 0\n    @arr = Array.new(length
# Code\n```ruby []\nclass SnapshotArray\n\n=begin\n  :type length: Integer\n=end\n  def initialize(length)\n    @current_snapshot_id = 0\n    @arr = Array.new(length) { [[-1, 0]]}\n  end\n\n\n=begin\n  :type index: Integer\n  :type val: Integer\n  :rtype: Void\n=end\n  def set(index, val)\n    @arr[index] << [@current_snapshot_id, val]\n  end\n\n\n=begin\n  :rtype: Integer\n=end\n  def snap()\n    @current_snapshot_id += 1\n    @current_snapshot_id - 1\n  end\n\n\n=begin\n  :type index: Integer\n  :type snap_id: Integer\n  :rtype: Integer\n=end\n  def get(index, snap_id)\n    snap_index = (@arr[index].bsearch_index {|saved_snapshot_id, _| saved_snapshot_id > snap_id } || @arr[index].size) - 1\n    @arr[index][snap_index].last\n  end\n\n\nend\n\n# Your SnapshotArray object will be instantiated and called as such:\n# obj = SnapshotArray.new(length)\n# obj.set(index, val)\n# param_2 = obj.snap()\n# param_3 = obj.get(index, snap_id)\n```
['Ruby']