Skip to content

Instantly share code, notes, and snippets.

@gamov
Last active August 29, 2015 14:01
Show Gist options
  • Save gamov/71111af88b0802e5ec2c to your computer and use it in GitHub Desktop.
Save gamov/71111af88b0802e5ec2c to your computer and use it in GitHub Desktop.
How to fake Date.current?
def adjusted real_value, type, &block
puts @data
key = [real_value, type]
if @data.include? key
@data[key][1]= Date.current # <- calls Date.current internally to keep track of oldest record,
# How can i alter the return of Date.current for it to return eg yesterday
else
trim_data
@data[key] = [yield, Date.current]
@data[key].first
end
def trim_data
if @data.size >= DATA_SIZE_LIMIT
@data.delete(@data.sort_by{|k,v| v.last}.first.first)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment