Question: Is there any better way to slice a word in ruby?
My solution:

```
str="TAMILNADU"
pairs=[]
numPairs= str.length-1
i=0
while i<numPairs do 
  pairs[i] = str.slice(i,2)
  i+=1
end

```

Result

```
["TA", "AM", "MI", "IL", "LN", "NA", "AD", "DU"] 

```

Answer: 
Another version:

```
str = "TAMILNADU"

(0...str.size-1).map{|x| str[x,2]} 
# => ["TA", "AM", "MI", "IL", "LN", "NA", "AD", "DU"]

```
Another way using a regex:

```
str.gsub(/(.)/,'\1\1')[1...-1].scan(/../)
  #=> ["TA", "AM", "MI", "IL", "LN", "NA", "AD", "DU"] 

```

or a variant:

```
str.gsub(/./) { |c| c*2 }[1...-1].scan(/../)

```

Any another:

```
a = []
e = str.each_char
loop do
  a << (e.next << e.peek)
end
a

```

Edit: I added the last method after the benchmarking was done, so I ran the benchmark myself. It was dead last. (I like it anyway.)