Comment by wood-porch 10 months ago Will this correctly retrieve 0 values? AFAIK 0 is falsey in Ruby``` return nil unless entry ``` 3 comments wood-porch Reply chowells 10 months ago No, Ruby is more strict than that. Only nil and false are falsely. wood-porch 10 months ago Doesn't that shift the problem to caching false then :D RangerScience 10 months ago you can probably always just do something like: def no_items? !items.present? end def items # something lone end memoize :items, ttl: 60, max_size: 10` just makes sure the expensive operation results in a truthy value, then add some sugar for the falsey value, done.
chowells 10 months ago No, Ruby is more strict than that. Only nil and false are falsely. wood-porch 10 months ago Doesn't that shift the problem to caching false then :D RangerScience 10 months ago you can probably always just do something like: def no_items? !items.present? end def items # something lone end memoize :items, ttl: 60, max_size: 10` just makes sure the expensive operation results in a truthy value, then add some sugar for the falsey value, done.
wood-porch 10 months ago Doesn't that shift the problem to caching false then :D RangerScience 10 months ago you can probably always just do something like: def no_items? !items.present? end def items # something lone end memoize :items, ttl: 60, max_size: 10` just makes sure the expensive operation results in a truthy value, then add some sugar for the falsey value, done.
RangerScience 10 months ago you can probably always just do something like: def no_items? !items.present? end def items # something lone end memoize :items, ttl: 60, max_size: 10` just makes sure the expensive operation results in a truthy value, then add some sugar for the falsey value, done.
No, Ruby is more strict than that. Only nil and false are falsely.
Doesn't that shift the problem to caching false then :D
you can probably always just do something like:
just makes sure the expensive operation results in a truthy value, then add some sugar for the falsey value, done.