Last active
August 29, 2015 14:01
-
-
Save gamov/71111af88b0802e5ec2c to your computer and use it in GitHub Desktop.
How to fake Date.current?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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