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: 
Yes there is:

```
irb(main):001:0> "TAMILNADU".chars.each_cons(2).map(&:join)
=> ["TA", "AM", "MI", "IL", "LN", "NA", "AD", "DU"]

```

See [the documentation of `Enumerable#each_cons`](http://ruby-doc.org/core-2.1.0/Enumerable.html#method-i-each_cons).
Another version:

```
str = "TAMILNADU"

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

```