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
我的目标是获取devices = "kv1101=3:4:6:8:2:5:7:1"
。但是,我该如何避免从第一个条目中删除冒号:
?顺序无关紧要。
3001, 3002, 3003
,因此有两件事情:首先没有3000
,其次,你的case语句永远不会起作用,因为d
永远不会在30000、30001、30002、30003
中。 - engineersmnky