Problems understanding Ruby code -


i have code:

all_backups = dir.entries[2..-1].sort.reverse max_backups = 20 unwanted_backups = all_backups[max_backups..-1] || [] 

i think gets entries in defined folder. [2..-1]? all_backups[max_backups..-1] || []?

dir.entries[2..-1] 

get elements index 2(means 3rd element of array) last index(last element of array). in ruby -1 means last element of array instance.

all_backups[max_backups..-1] || [] 

all_backups[max_backups..-1] gives nil, assign empty array [] variables other wise returned array all_backups[max_backups..-1].


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

spring cloud - How to configure SpringCloud Eureka instance to point to https on non standard port -

javascript - Bootstrap Popover: iOS Safari strange behaviour -