Reputation: 12092
I have an hash like this: value = {Fri, 14 Oct 2016=>58.0}
How to return the date's value which is 58.0
?
Not much help from the docs.
Have tried value["#{DateTime.now}"]
but that returns 0
.
Upvotes: 1
Views: 304
Reputation: 23713
If your key is a DateTime
object you should do value[date_object]
. So, if you created your hash like:
key = DateTime.now
value = {key=>58.0}
You should access it like: value[key]
If you know the string representation of that DateTime
object, you can always convert it to DateTime
by using the strptime method
Upvotes: 1