# Array iterate grammar rules

**URL:** <https://www.ruby-forum.com/t/array-iterate-grammar-rules/119459>\
**Category:** Ruby\
**Created:** [November 7, 2007, 5:13am UTC](https://www.ruby-forum.com/t/array-iterate-grammar-rules/119459 "2007-11-07T05:13:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dreamwave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7feea3/32.png) [@dreamwave](https://www.ruby-forum.com/u/dreamwave)\
**Post date:** [November 7, 2007, 5:13am UTC](https://www.ruby-forum.com/t/array-iterate-grammar-rules/119459/1 "2007-11-07T05:13:12Z")

</div>

If i had an array containing a lot of words, and i wanted to add grammar  
rules to those words, ie make words plural how would i duplicate the  
original element and then modify that element with the grammar rule, and  
id hope to iterate this for all the words and apply grammar rules via a  
defined method.

IE:

array = [“sky”,“knife”,“kitty”]

after applying gsub or some other method such as inject or collect…the  
array would become…

array #=\> [“sky”,“skies”,“knife”,“knives”,“kitty”,“kitties”]  
and whatnot ect ect.

id rather not gsub all the grammar rules lol.

Any ideas?

Thanks!

-Mac

---

<div class="post-metadata">

**Author:** ![dreamwave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7feea3/32.png) [@dreamwave](https://www.ruby-forum.com/u/dreamwave)\
**Post date:** [November 7, 2007, 6:03am UTC](https://www.ruby-forum.com/t/array-iterate-grammar-rules/119459/2 "2007-11-07T06:03:54Z")

</div>

On Nov 6, 9:16 pm, Michael L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> after applying gsub or some other method such as inject or collect…the  
> array would become…
> 
> array #=\> [“sky”,“skies”,“knife”,“knives”,“kitty”,“kitties”]  
> and whatnot ect ect.
> 
> id rather not gsub all the grammar rules lol.

irb(main):001:0\> require ‘rubygems’  
=\> true  
irb(main):002:0\> require ‘active\_support’  
=\> true  
irb(main):003:0\> array = [“sky”,“knife”,“kitty”]  
=\> [“sky”, “knife”, “kitty”]  
irb(main):004:0\> plurals = array.map{ |word| word.pluralize }  
=\> [“skies”, “knives”, “kitties”]  
irb(main):005:0\> array  
=\> [“sky”, “knife”, “kitty”]  
irb(main):006:0\> array.zip( plurals )  
=\> [[“sky”, “skies”], [“knife”, “knives”], [“kitty”, “kitties”]]  
irb(main):007:0\> array.zip( plurals ).flatten  
=\> [“sky”, “skies”, “knife”, “knives”, “kitty”, “kitties”]
