I'm currently populating a simple array like so:
queues = %w(rate_limit_000 rate_limit_001 rate_limit_002 rate_limit_003 rate_limit_004 rate_limit_005 rate_limit_006 rate_limit_007 rate_limit_008 rate_limit_009 rate_limit_010 rate_limit_011 rate_limit_012)
That's ripe for refactoring. So what's the easiest way to build that array without manually adding items?
The only difference between the item names are those last 3 digits, which should always be 3 digits, but I do need to set a limit on how high it goes.
What about using String#%?
(0..12).map { |i| "rate_limit_%03d" % i }
# => ["rate_limit_000", "rate_limit_001", "rate_limit_002", ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With