I'm using Ruby and have a hash, call it foo, and its value is an Array with a fixed length of 2.
How can I update one of the indexes within the hash values array? Here's an example:
foo.each do |k, v|
if k == 'some value'
foo[k] = update v[0]
foo[k] = update v[1]
end
end
Further clarification:
I'm looping through a file and inside I want to to see if the current line matches the hash key k. If it does I want to update the timestamp in the values array, which is stored in v[1].
# read lines from the input file
File.open(@regfile, 'r') do |file|
file.each_line do |line|
# cache control
cached = false
# loop through @cache
@cache.each do |k, v|
# if (url is cached)
if line == k
# update the timestamp
@cache[k] = Time.now.getutc # need this to be put in v[1]
# set cached to true
cached = true
end
end
# if cached go to next line
next if cached
# otherwise add to cache
updateCache(line)
end
end