device_target = ["3001", "3002", "3003"]
devices = ",kv1101="
device_target.map {|d|
case d
when "30000" #desktop
devices << ":9"
when "30001" # smartphone
devices << ":3:4:6:8"
when "30002" #tablet
devices << ":2:5:7"
when "30003" #feature_phone
devices << ":1"
end
My target is to get devices = "kv1101=3:4:6:8:2:5:7:1". But, how can I avoid this colon : from the first entry? The order doesn't matter.
Store the values in an array and then use the join method:
devices = ",kv1101="
my_devices = []
device_target.map {|d|
case d
when "30000" #desktop
my_devices << "9"
when "30001" # smartphone
my_devices += ["3","4","6","8"]
when "30002" #tablet
my_devices += ["2","5","7"]
when "30003" #feature_phone
my_devices << "1"
end}
devices << my_devices.join(":")
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